Search code examples
node.jsangularnpmwebpackhtml-webpack-plugin

const INLINE = 'inline'; with npm related commands


Today I was trying to work on Angular2 (template https://akveo.github.io). As per installation guide, I ran following commands.

I have installed Node.js v6.9.1.

  1. npm install --Worked fine.
  2. npm server --Failed with below error.

    E:\........\node_modules\script-ext-html-webpack-plugin\index.js:3 const INLINE = 'inline'; ^^^^^ SyntaxError: Use of const in strict mode. at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25)

After many random searches and failing to resolve it, I decided to think about it with a calm head. To me it looks like it is a problem with ES2015/ES6. Package script-ext-html-webpack-plugin uses const variable which is a ES2016 feature. However system is unable to resolve it.

Also this problem can come with any package like hapi, selinium etc. But everything should have same solution I guess.

I have tried many related commands on the installation guide of the website mentioned above but nothing works and ends with same error. I have also many have faced same issue online but nothing concrete is visible as answer. Could anyone help me out?


Solution

  • Update

    Below approach has also fixed many of my colleague's machine who were facing some random errors with nodejs.


    This problem is resolved in at least my machine. I am certainly not a person who understand nodejs completely but got it working after some googling. The solution given below may be common to many other issues I guess.

    The system I am working has Windows 10 as Operating System and has 64 bit processor.

    1. Go to control panel and uninstall nodejs (just to make sure you do not have traces of any previous install).
    2. Install latest version of nodejs from their website (I installed v6.9.1 for 64 bit processor).
    3. Go to Environment variables for system (just type environmental variables in start menu if using Windows 10) and edit the Path. Delete ‘C:/Program Files (x86)/nodejs’ (as I had installed 64 bit nodejs). This ensures when using command you do not use any other previously installed nodejs.
    4. Start command prompt in Admin mode and navigate to your project and run npm install.
    5. In case you get any/some error, then run npm info graceful-fs -v or npm info graceful-fs whichever runs in your machine.
    6. Then run npm update -g npm.
    7. Then run npm install again and this time it should work.
    8. Run npm start and everything should work fine.
    9. On running website, sometimes we see any other issue and that can be seen from console logs. But good thing is, console logs also tell you the problem. In most cases its related to 32 bit and 64 bit processor due to our recent changes. In my case, I was facing issue with SASS configuration due to 32/64 bit machine and console log asked me to run npm rebuild node-sass to fix the issue.
    10. Go back to command prompt, hit Ctrl+C to stop npm server. Run node rebuild node-sass. Run npm start again and everything should be working.

    Hope it helps.