[英]'console' is 'undefined in the shell by using webpack with node.js
I have a file my-script.js
that only returns this:我有一个文件
my-script.js
只返回这个:
console.log('Hi I'm working')
When I type in shell only当我只输入 shell
node my-script.js
This works successfully.这成功了。 But I'd like it to work too when I typed in just this:
但是当我输入以下内容时,我希望它也能正常工作:
npm start
How to make it work?如何让它发挥作用? Because it is generating an error message:
因为它正在生成错误消息:
Line: 1 Error: console is undefined Code: 800A1391 Source: Microsoft JScript runtime error
行:1 错误:控制台未定义代码:800A1391 来源:Microsoft JScript 运行时错误
I have a package.json file that points to this file to be the start
but this is not resolving.我有一个 package.json 文件,该文件指向该文件作为
start
,但这并没有解决。
Here is my package.json file:这是我的 package.json 文件:
{
"name": "my-app",
"version": "1.0.0",
"main": "my-script.js",
"scripts": {
"start": "my-script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"webpack": "^4.41.2"
},
"description": ""
}
Use node
in start
script在
start
脚本中使用node
{
"name": "my-app",
"version": "1.0.0",
"main": "my-script.js",
"scripts": {
"start": "node my-script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"webpack": "^4.41.2"
},
"description": ""
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.