#

image

  • 原因:是因为没有找到 npm 这个目录,在报错的目录的 npm 的上级目录下将 npm 重命名为 npm_,重新创建一个 npm 目录(C:\Users\Administrator\AppData\Roaming),我这边是因为在这个路径中有个名为 npm 的文件(不是目录),所以命令行不能正确识别。我是先把这个 npm 的文件重名为 npm.bak(做一个备份)然后在新建一个 npm 的目录(不重命名的话提示提示目录已存在,其实就是那个 npm 的文件,应该自动生成而又没有被正确识别为目录)

# 使用 npm 下载时,出现错误 Unexpected end of JSON input while parsing near···

fe 解决方法:先清除缓存,再重新安装

清除缓存:运行 npm cache clean --force

重新安装: npm install


# angular 项目里报错,@ngtools module build failed

ERROR in ./src/utils/common.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Users/xyingliu/self/学习/code/angular/learning/src/utils/common.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Users/xyingliu/self/学习/code/angular/learning/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:933:23)
    at plugin.done.then (/Users/xyingliu/self/学习/code/angular/learning/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)

# npm ERR! errno 126 的解决办法

# 解决方法:

cd 到项目目录 然后依次执行下面的命令 rm -rf node_modules rm package-lock.json npm cache clear --force npm install

# 网上看别人遇到的 npm ERR! Error: ENOENT, lstat

# 解决办法一:

npm config set user 0
npm config set unsafe-perm true

# 解决办法二:升级 node 版本再来一次

npm install -g n
n stable

# 解决办法三:权限问题,加个 sudo 再来一次

sudo npm install -g module_name

# 运行代码时,failed Error: not found: python2

# 错误如下:

gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python2\n    at getNotFoundError (C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:13:12)\n    at F (C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:68:19)\n    at E (C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:80:29)\n    at C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:89:16\n    at C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\isexe\\index.js:42:5\n    at C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:153:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` failed Error: not found: python
gyp verb `which` failed     at getNotFoundError (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed  python { Error: not found: python
gyp verb `which` failed     at getNotFoundError (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python\n    at getNotFoundError (C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:13:12)\n    at F (C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:68:19)\n    at E (C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:80:29)\n    at C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\which\\which.js:89:16\n    at C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\isexe\\index.js:42:5\n    at C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:153:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb could not find "python". checking python launcher
gyp verb could not find "python". guessing location
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error
gyp ERR! stack     at PythonFinder.failNoPython (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at callback (C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\graceful-fs\polyfills.js:295:20)
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:153:21)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\v-liuxiaoying.ea\\code\\new\\p2p-source-item-fe\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\v-liuxiaoying.ea\code\new\p2p-source-item-fe\node_modules\node-sass
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0

# 解决方法:

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
npm install node-sass
yarn install

# npm 报错清除 npm 缓存

npm ERR! code Z_BUF_ERROR
npm ERR! errno -5
npm ERR! zlib: unexpected end of file

遇到上述错误,执行以下命令,清除 npm 缓存

npm cache clean --force

# 安装 npm 新版本出现以下问题

  • 原因:是因为没有找到 npm 这个目录,在报错的目录的 npm 的上级目录下将 npm 重命名为 npm_,重新创建一个 npm 目录(C:\Users\Administrator\AppData\Roaming),我这边是因为在这个路径中有个名为 npm 的文件(不是目录),所以命令行不能正确识别。我是先把这个 npm 的文件重名为 npm.bak(做一个备份)然后在新建一个 npm 的目录(不重命名的话提示提示目录已存在,其实就是那个 npm 的文件,应该自动生成而又没有被正确识别为目录)

# 使用 npm 下载时,出现错误 Unexpected end of JSON input while parsing near···

# 解决方法:先清除缓存,再重新安装

清除缓存:运行 npm cache clean --force

重新安装: npm install

# node 安装过程中遇到的问题-update-notifier

   let notifier = require('update-notifier')({pkg})
      ^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

# 原因:node 安装版本过低