简体   繁体   中英

'console' is 'undefined in the shell by using webpack with node.js

I have a file my-script.js that only returns this:

console.log('Hi I'm working')

When I type in shell only

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

I have a package.json file that points to this file to be the start but this is not resolving.

Here is my package.json file:

{
  "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

{
  "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": ""
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM