Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

javascript - Cannot find module 'internal/fs' after upgrading to node 7

We've recently tried to upgrade to node v7.0.0 on our build server, but started to have issues during the application build task failing on the "bower_concat" step:

Loading "bower-concat.js" tasks...ERROR
Error: Cannot find module 'internal/fs'

What we have installed:

  • node v7.0.0 (installed via yum "nodesource" repository)
  • npm 4.0.1
  • using grunt (if this is relevant)
  • grunt-bower-concat 0.6.0

The grunt build task configuration:

grunt.registerTask(
    'build:prod', [
        'clean:prod',
        'copy:prod',
        'replace',
        'bower_concat',
        'ngtemplates',
        'concat',
        'uglify',
        'cssmin',
        'injector:prod',
        'copy:cssfix',
        'copy:dist',
        'bowercopy:dist',
        'bowercopy:fonts',
        'template:setProdVersion'
    ]
);

And the grunt bower_concat task:

bower_concat: {
    all: {
        dest: '<%= app.build %>/bower.js',
        cssDest: '<%= app.build %>/bower.css',
        dependencies: {
            'bootstrap': 'jquery'
        },
        mainFiles: {
            "angular-app-modules": [
                "app/dist/angular-app-modules.min.js",
                "app/dist/angular-app-modules.min.css"
            ]
        }
    }
}, 

Note that it works without any problems on node v6.9.0.

What can be causing the issue? Can we workaround the problem without downgrading to node v6?


There is also this relevant issue, but, as of now, the information there does not help in our case.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, open the console as administrator (or in the terminal with sudo if it is a Linux) and:

npm cache clean

For npm 5 and later

npm cache clean --force

Edit:

For windows you might fail to clean the cache, so you can remove the cache manually by deleting all the following folder content:

C:Users<USER-NAME>AppDataRoaming
pm-cache

Thanks "superwf", this case might happen for some, but I never had to do this (maybe because of my lowest security level?!).

End Edit.


Then go back to the normal console (not administrator or root), return to your project directory where the package.json is located, and then delete the node_modules folder from your project, remove it completely, and then install node modules again inside your project folder:

npm install

You might need to update your modules before installing modules again. I recommend this, but be careful of breaking changes if there are any major version changes in your modules. This module npm-check-updates can help you to check the latest version and update them.

Also, you maybe need to install the latest global modules as well, check updates by:

ncu -g

or

npm outdated -g

If you're still stuck, you might need to remove the global node_modules folder and reinstall what you want again.


Edit:

Yarn option: Some people ended with the same issues even with the cleanup procedures, actually you save your time a lot using Yarn. Personally, I started to use yarn instead of traditional npm i, I can guarantee it is faster, and save your time, and your head from npm headaches.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...