[英]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. 我应该安装
react
和react-dom
还webpack
+ 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. 我将它们全部安装在本地(
react
和react-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. 在本地安装某些组件时,有两个选择。
./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.