找不到模块'webpack-cli'

时间:2018-04-16 10:49:50

标签: firebase webpack ecmascript-6

我想让es6进入我的项目,所以我使用了这个教程this tutorial 当我尝试在cmd中写'webpack'时,我收到错误

    Done in 8.99s.
{ Error: Cannot find module 'webpack-cli'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at runCommand.then.result (C:\Users\adirz\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js:62:14)
    at process._tickCallback (internal/process/next_tick.js:109:7) code: 'MODULE_NOT_FOUND' }

的package.json

   {
  "name": "functions",
  "scripts": {
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.1"
  },
  "devDependencies": {
    "ts-loader": "^4.2.0",
    "typescript": "^2.5.3",
    "webpack": "^4.5.0",
    "webpack-cli": "^2.0.14",
    "webpack-node-externals": "^1.7.2"
  },
  "private": true
}

我的文件夹结构

enter image description here

5 个答案:

答案 0 :(得分:11)

尝试使用:npm i -g webpack-cli

以下是github上的官方问题:https://github.com/webpack/webpack-cli/issues/191

答案 1 :(得分:3)

将全局安装的软件包链接到您的项目

  

npm link webpack-cli

答案 2 :(得分:2)

这为我解决了问题

sudo chown -R $USER /usr/local/lib/node_modules
npm i -g webpack-cli

https://flaviocopes.com/npm-fix-missing-write-access-error/

答案 3 :(得分:0)

我也有类似的错误。对我来说,答案是确保我的项目的整个路径没有空格、&符号(&)或任何其他奇怪的字符。

答案 4 :(得分:0)

对我来说问题是我没有使用“sudo”权限。 如果您使用的是基于 linux 的系统,请尝试输入 sudo npm i -g webpack-cli