【问题标题】:Why does npm start give me "Error: Cannot find module './keywords'"?为什么 npm start 给我“错误:找不到模块'./keywords'”?
【发布时间】:2021-09-04 12:36:44
【问题描述】:

尝试使用 npm start 和 Create React App 来启动我的 React 应用程序,但收到此错误:

node:internal/modules/cjs/loader:943
  throw err;
  ^

Error: Cannot find module './keywords'
Require stack:
- D:\social-ribbon\node_modules\ajv-keywords\index.js
- D:\social-ribbon\node_modules\webpack\node_modules\schema-utils\src\validateOptions.js
- D:\social-ribbon\node_modules\webpack\node_modules\schema-utils\src\index.js
- D:\social-ribbon\node_modules\webpack\lib\SourceMapDevToolPlugin.js
- D:\social-ribbon\node_modules\webpack\lib\WebpackOptionsApply.js
- D:\social-ribbon\node_modules\webpack\lib\webpack.js
- D:\social-ribbon\node_modules\react-scripts\scripts\start.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Function.Module._load (node:internal/modules/cjs/loader:773:27)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (D:\social-ribbon\node_modules\ajv-keywords\index.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19) {
  requireStack: [
    'D:\\social-ribbon\\node_modules\\ajv-keywords\\index.js',
    'D:\\social-ribbon\\node_modules\\webpack\\node_modules\\schema-utils\\src\\validateOptions.js',
    'D:\\social-ribbon\\node_modules\\webpack\\node_modules\\schema-utils\\src\\index.js',
    'D:\\social-ribbon\\node_modules\\webpack\\lib\\SourceMapDevToolPlugin.js',
    'D:\\social-ribbon\\node_modules\\webpack\\lib\\WebpackOptionsApply.js',
    'D:\\social-ribbon\\node_modules\\webpack\\lib\\webpack.js',
    'D:\\social-ribbon\\node_modules\\react-scripts\\scripts\\start.js'
  ]
}

有人建议搜索名为“keywords”的文件,但该词仅作为ajv-keywordscss-color-keywords 的一部分出现在文件中。其他人建议重新安装整个 node-modules 文件夹,但这听起来有点激烈。我现在请你帮忙。感谢您的帮助。

【问题讨论】:

  • 是否有一个名为keywords.js 的文件?如果有,您能否分享一下您的文件夹结构?
  • 正如我所说,没有文件名包含keywords,它仅作为这两个包/模块的一部分出现在 in 文件中。
  • 您能否添加代码,在哪里使用来自keywords 模块的导入?这样就更容易识别问题了。
  • 注意到我没有keywords 包,所以我安装了它,但它仍然显示相同的错误。我再次搜索了keywords,它显然出现了,但只出现在package-lock.jsonpackage.jsonyarn.lock 中(试图搬到Yarn,然后,一切都从那里走下坡路)。

标签: node.js npm create-react-app npm-start


【解决方案1】:

假设您将其作为“关键字”导入,

import Keywords from './keywords' 更改为import Keywords from 'keywords'

node_modules导入包时不需要使用相对路径。

【讨论】:

  • 我实际上从未导入过这个包。我不知道为什么会这样。
猜你喜欢
  • 2020-11-08
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多