Cannot find module 'internal/fs' after upg

2019-01-31 16:41发布

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.

17条回答
三岁会撩人
2楼-- · 2019-01-31 16:55

Ran into this issue after a Node v4.X to v7.8.0 upgrade. Reinstalling NPM and a latest check, got me to a working NPM v4.5.0.

curl -L https://www.npmjs.com/install.sh | sh
npm install npm@latest -g
查看更多
欢心
3楼-- · 2019-01-31 16:57

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>\AppData\Roaming\npm-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.

查看更多
闹够了就滚
4楼-- · 2019-01-31 17:02

The solution that worked for me was to

1) Delete node_modules/

sudo rm -R node_modules/ 

2) Re-run gulp

gulp

查看更多
\"骚年 ilove
5楼-- · 2019-01-31 17:03

Run

sudo rm -rf /usr/local/lib/node_modules/npm

Again npm install. It will Works

查看更多
该账号已被封号
6楼-- · 2019-01-31 17:04

I use the n tool to manage switching between node (and the bundled npm) versions.

To fix this error, I simply removed npm from the global space (macOS): sudo rm -rf /usr/local/lib/node_modules/npm

I then re-ran sudo n latest. This will re-install npm. When switching back to previous version of node just run sudo n 4.3.2.

To summarise:

> sudo rm -rf /usr/local/lib/node_modules/npm
> sudo n latest
> node --version
v7.7.1
> npm --version
4.1.2
> sudo n 4.3.2
> npm --version
2.14.12
查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-01-31 17:06

In my case clearing the cache (OSX) did not work. I use n to manage node which causes npm to potentially be out of date. According to n docs you can update npm with:

curl -0 -L https://npmjs.org/install.sh | sudo sh
查看更多
登录 后发表回答