简体   繁体   English

Webpack无法在我的node.js项目中工作。 fsevents

[英]Webpack not working in my node.js project. fsevents

I'm currently trying to implement this tutorial: 我目前正在尝试实施本教程:

https://www.typescriptlang.org/docs/handbook/react-&-webpack.html https://www.typescriptlang.org/docs/handbook/react-&-webpack.html

I'm supposed to install react and react-dom and also webpack + typescript + awesome-typescript-loader + source-map-loader , and that's what I did. 我应该安装reactreact-domwebpack + typescript + awesome-typescript-loader + source-map-loader ,这就是我所做的。 I also installed webpack-cli accordingly to instructions that I got from the command line. 我还根据从命令行获得的说明安装了webpack-cli

I installed all of them locally (the react and react-dom as PROD and the rest as DEV dependencies).Currently I don't have any packages installed globally. 我将它们全部安装在本地( reactreact-dom作为PROD,其余作为DEV依赖项)。目前我没有在全球安装任何软件包。

After this, that's my package.json file: 之后,这就是我的package.json文件:

{
  "name": "reactandwebpack-tutorial",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "awesome-typescript-loader": "^5.2.0",
    "source-map-loader": "^0.2.3",
    "typescript": "^2.7.2",
    "webpack": "^4.16.4",
    "webpack-cli": "^3.1.0"
  },
  "dependencies": {
    "@types/react": "^16.4.7",
    "@types/react-dom": "^16.0.6",
    "react": "^16.4.2",
    "react-dom": "^16.4.2"
  }
}

At this point, when I run npm ls I get a bunch of errors, because of some optional dependency of webpack that apparently is missing (all the errors in the tree are inside webpack and below fsevents as following): 此时,当我运行npm ls时,由于出现了一些可选的webpack依赖关系而明显丢失了错误(树中的所有错误都在webpack并在fsevents下方,如下所示):

webpack@4.16.4
(...)watchpack@1.6.0
     (...)chokidar@2.0.4
          (...)fsevents@1.2.4 -> UNMET OPTIONAL DEPENDENCY
               And everything below fsevents is also marked with UNMET DEPENDENCY

And when I run webpack command, I get a "webpack not recognized error". 当我运行webpack命令时,出现“无法识别webpack的错误”。

Anyone can help? 有人可以帮忙吗? I've been trying to wrap my head around this for a while. 我一直在想办法解决这个问题。

PS: PS:

Npm -v 5.6.0
Node -v 8.11.3 //(that's what I get from the terminal, 
               //VSCode "About" tells me something different, I don't know why).

Using Visual Code

Version 1.24.0
Date 2018-06-06T17:35:40.560Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

SOLVED 解决了

Not sure the reason but it had something to do with the ./bin folder with the webpack-cli "ambient variable" not being available (I don't know it that would be the most accurate description). 不知道原因,但是与./bin文件夹有关,而webpack-cli“环境变量”不可用(我不知道这是最准确的描述)。

When I try to run webpack , I get "not recognized error". 当我尝试运行webpack ,出现“无法识别的错误”。

But when I run nodemodules\\.bin\\webpack-cli it works normally. 但是当我运行nodemodules\\.bin\\webpack-cli它可以正常工作。

Everything is installed locally. 一切都在本地安装。

I can also run it with options, like nodemodules\\.bin\\webpack-cli --help 我也可以使用选项运行它,例如nodemodules\\.bin\\webpack-cli --help

The reason is because it was not linked to your env. 原因是它没有链接到您的环境。 When you install something globally, you have access to it everywhere, hence it works just by doing webpack . 在全局安装某些东西时,您可以在任何地方访问它,因此只需执行webpack Since you installed everything locally, the binaries are located inside node_modules/.bin . 由于您在本地安装了所有内容,因此二进制文件位于node_modules/.bin

You have two options when you install something locallly. 在本地安装某些组件时,有两个选择。

  1. Use npm scripts (npm run build, watch... whatever). 使用npm脚本(npm运行构建,监视……等等)。
  2. ./node_modules/.bin/moduleName --flags

It is easier to create a npm script and add all the commands there. 创建npm脚本并在其中添加所有命令会更容易。

If you run "webpack", The CLI will find global webpack with is installed by (npm install webpack -g). 如果运行“ webpack”,则CLI会找到(npm install webpack -g)安装的全局webpack。 To use webpack from local project. 要使用本地项目中的webpack。 you should it to npm script. 您应该将其保存为npm脚本。

package.json 的package.json

{
    "script": {
        "start": "webpack"
    }
}

By doing this, you can run npm start to run webpack. 这样,您可以运行npm start来运行webpack。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js 中的 fsevents 是什么? - What is fsevents in Node.js? orderByChild(),limitTo()在我的angularjs项目中不起作用。 - orderByChild(), limitTo() not working in my angularjs project.? 我正在使用node.js并为学生开发协作工具,我想在我的节点项目中使用fabric js但是它不能正常工作 - I am using node.js and working on a collaborative tool for students and i want to use fabric js in my node project but it is not working 我的正则表达式不起作用Node.js吗? - My regular expression is not working Node.js? 测试AWS服务无法按预期运行时,我的Node.JS项目中的sinon.spy - sinon.spy in my Node.JS project when testing an AWS service not working as expected 更新 Node.js 后节点项目停止工作 - Node project stopped working after I updated Node.js Node.js + Webpack + TypeScript:使用源文件访问项目路径(不是使用项目) - Node.js + Webpack + TypeScript: access to path of project with source files (not usage project) Node.js 不工作? - Node.js is not working? Webpack / node.js构建,webpack-dev-server是否可以将文件提供到我的公共目录? - Webpack/node.js build, is it possible for webpack-dev-server to serve files to my public directory? 使用Node.JS - Working with Node.JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM