错误:找不到模块'@angular-devkit/build-angular/package.json'
Posted
技术标签:
【中文标题】错误:找不到模块\'@angular-devkit/build-angular/package.json\'【英文标题】:Error: Cannot find module '@angular-devkit/build-angular/package.json'错误:找不到模块'@angular-devkit/build-angular/package.json' 【发布时间】:2021-05-24 14:30:49 【问题描述】:当我在终端中执行ng s --open
时,出现以下错误。
[error] Error: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\index.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\commands\serve-impl.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\index.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\utilities\json-schema.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\models\command-runner.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\lib\cli\index.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\lib\init.js
- C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.resolve (node:internal/modules/cjs/helpers:98:19)
at WorkspaceNodeModulesArchitectHost.resolveBuilder (C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:85:41)
at ServeCommand.initialize (C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:139:55)
at async ServeCommand.validateAndRun (C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\models\command.js:127:9)
at async Object.runCommand (C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\models\command-runner.js:204:24)
at async default_1 (C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\@angular\cli\lib\cli\index.js:80:31)
如果我在项目目录执行npm install
,我会得到以下错误日志
D:\application-new-ui\application-ui-master>npm install
npm ERR! code 1
npm ERR! path D:\application-new-ui\application-ui-master\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Users\santhosh.k\AppData\Roaming\npm\node_modules\node\bin\node.exe D:\application-new-ui\application-ui-master\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli 'C:\\Users\\santhosh.k\\AppData\\Roaming\\npm\\node_modules\\node\\bin\\node.exe',
npm ERR! gyp verb cli 'D:\\application-new-ui\\application-ui-master\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli 'rebuild',
npm ERR! gyp verb cli '--verbose',
npm ERR! gyp verb cli '--libsass_ext=',
npm ERR! gyp verb cli '--libsass_cflags=',
npm ERR! gyp verb cli '--libsass_ldflags=',
npm ERR! gyp verb cli '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@15.8.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed at getNotFoundError (D:\application-new-ui\application-ui-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed at F (D:\application-new-ui\application-ui-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed at E (D:\application-new-ui\application-ui-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed at D:\application-new-ui\application-ui-master\node_modules\which\which.js:89:16npm ERR! gyp verb `which` failed at D:\application-new-ui\application-ui-master\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed at D:\application-new-ui\application-ui-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:196:21)
npm ERR! gyp verb `which` failed python2 Error: not found: python2
npm ERR! gyp verb `which` failed at getNotFoundError (D:\application-new-ui\application-ui-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed at F (D:\application-new-ui\application-ui-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed at E (D:\application-new-ui\application-ui-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed at D:\application-new-ui\application-ui-master\node_modules\which\which.js:89:16npm ERR! gyp verb `which` failed at D:\application-new-ui\application-ui-master\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed at D:\application-new-ui\application-ui-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:196:21)
npm ERR! gyp verb `which` failed code: 'ENOENT'
npm ERR! gyp verb `which` failed
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python C:\Python39\python.EXE
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack File "<string>", line 1
npm ERR! gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:327:12)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:378:20)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1067:16)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command "C:\\Users\\santhosh.k\\AppData\\Roaming\\npm\\node_modules\\node\\bin\\node.exe" "D:\\application-new-ui\\application-ui-master\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\application-new-ui\application-ui-master\node_modules\node-sass
npm ERR! gyp ERR! node -v v15.8.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\santhosh.k\AppData\Local\npm-cache\_logs\2021-02-22T10_37_55_073Z-debug.log
【问题讨论】:
【参考方案1】:更新到 Angular 12 后,我的应用程序遇到了同样的问题。
尝试在 npm 命令行末尾添加--force
,它解决了
给我的问题。
npm install --save-dev @angular-devkit/build-angular --force
还要检查您的 Node 版本,Angular 不支持 Node (16.8.0)。
【讨论】:
【参考方案2】:尝试通过运行rm -rf [your_node_modules]
删除您的节点模块,然后再次运行 npm i。
【讨论】:
【参考方案3】:您可以删除节点模块并再次重新运行脚本。请按照以下步骤操作:
如果您已经在可视代码等 IDE 中打开了应用程序,请将其关闭。 以 ADMIN 用户身份打开 cmd 并在进入项目文件夹后将 rimraf 作为 npm 包安装。npm install rimraf
输入命令rimraf node_modules
删除后,请重新安装节点模块。 npm istall
【讨论】:
【参考方案4】:将@angular-devkit/build-angular
安装为开发依赖项。这个包是 Angular 中新引入的。
npm install --save-dev @angular-devkit/build-angular
或
yarn add @angular-devkit/build-angular --dev
【讨论】:
【参考方案5】:就我而言,问题是 NODE_ENV 环境变量设置为 production
。将其设置为 development
并运行 npm install 解决了这个问题。
我的猜测是 @angular-devkit/build-angular 包以某种方式检查 NODE_ENV 环境变量,因此当设置为 production
时未正确安装,因为它是开发依赖项。
【讨论】:
【参考方案6】:删除node_modules
文件夹。运行npm install
应该可以解决问题。
【讨论】:
以上是关于错误:找不到模块'@angular-devkit/build-angular/package.json'的主要内容,如果未能解决你的问题,请参考以下文章
找不到模块'@angular-devkit/schematics/tasks'
基本角度应用程序无法运行,错误模块构建失败:找不到模块../@angular-devkit/src/babel/X
找不到模块“@angular-devkit/build-angular”
如何修复“找不到模块'@angular-devkit/schematics'”
发生未处理的异常:找不到模块'@angular-devkit/build-angular/package.json'
离子应用程序:发生未处理的异常:找不到模块“@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/uti