NPM在启动时显示无法找到模块' safe-buffer'

时间:2018-04-20 09:04:50

标签: node.js npm restful-url npm-start

我正在尝试创建一个Node Restful API服务,但是npm在启动时给了我一个错误。在命令提示符下,我输入了以下内容:

D:\xampp\htdocs\todoListApi>npm run start
  

todolistapi@1.0.0启动D:\ xampp \ htdocs \ todoListApi

     

nodemon server.js

显示以下错误

[nodemon] 1.17.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
internal/modules/cjs/loader.js:550
    throw err;
    ^

Error: Cannot find module 'safe-buffer'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
at Function.Module._load (internal/modules/cjs/loader.js:475:25)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)


     at Object.<anonymous> (D:\xampp\htdocs\todoListApi\node_modules\readable-str
    eam\lib\_stream_readable.js:55:14)

    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todolistapi@1.0.0 start: `nodemon server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todolistapi@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\admin\AppData\Roaming\npm-cache\_logs\2018-04-20T06_50_15_
033Z-debug.log

D:\xampp\htdocs\todoListApi>npm install mongoose --sav
npm WARN todolistapi@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fse
vents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}

相反它应该从npm开始并将结果显示为

  

todo list启动RESTful API服务器:3000

请指导我如何克服这一点。

2 个答案:

答案 0 :(得分:0)

以下步骤对我有用:

  • 从控制面板卸载Node.js
  • 转到C:/ Users / Admin / AppData / Roaming
  • 手动删除npmnpm-cache

再次尝试安装node.js.

答案 1 :(得分:0)

尝试使用npm cache clean --force,如果仍然无效,请尝试完全重新安装NPM / Node:)