0

我在使用命令 npm install chalk 安装节点版本 14 的粉笔模块时遇到了这个问题,面对这个问题找不到任何解决方案。

包.json 文件

  "name": "notes-app",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "jayant",
  "license": "ISC",
  "dependencies": {
    "chalk": "^5.0.0"
  },
  "type": "module"
}

app.js 文件

import chalk from 'chalk';

console.log(chalk.blue('Hello world!'));

使用节点版本 14 运行 app.js 时出现此错误

    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\previous data\Jayant\Programs\node-tutorials\notes-app\node_modules\chalk\source\node_modules\' imported from C:\previous data\Jayant\Programs\node-tutorials\notes-app\node_modules\chalk\source\index.js
    at packageMainResolve (internal/modules/esm/resolve.js:458:9)
    at packageResolve (internal/modules/esm/resolve.js:601:14)
    at moduleResolve (internal/modules/esm/resolve.js:646:14)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:692:13)
    at Loader.resolve (internal/modules/esm/loader.js:97:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
    at link (internal/modules/esm/module_job.js:41:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
4

0 回答 0