为什么 npm start 给我“错误:找不到模块 './keywords'”?

问题描述

尝试使用 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 文件夹,但这听起来有点过激。我现在请你帮忙。感谢您的帮助。

解决方法

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

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...