admin管理员组

文章数量:1134247

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.

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.

Share Improve this question edited Jan 20, 2018 at 23:13 Nathan 1,6912 gold badges18 silver badges31 bronze badges asked Oct 28, 2016 at 15:42 alecxealecxe 473k126 gold badges1.1k silver badges1.2k bronze badges 3
  • It sounds like the previous version was not properly replaced or permissions are screwy, but this isn't nearly enough info to tell. I've seen this before (while running our build cluster) with other modules, but it was always a partially bad install and I usually just respin the box. – ssube Commented Oct 28, 2016 at 15:45
  • @ssube thanks, yeah, I tend to think this is a bad install as well (not sure, how to reliably verify it though). When I was google-searching this, I've seen people reinstalling node helped when a similar error was thrown. I've tried that numerous times, but, I guess, I need to start with a completely fresh box. Also, some people reported that installing npm 4 alongside with node 7 helped to solve the problem..but I have npm 4 installed. Okay, I'll see if having a fresh box will help. – alecxe Commented Oct 28, 2016 at 15:54
  • 3 Try cd'ing into node_modules/bower-concat and then run npm install from there. Then try running your build task again from proj root. Any improvement? – BigHeadCreations Commented Oct 31, 2016 at 7:28
Add a comment  | 

17 Answers 17

Reset to default 66 +50

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.

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

In linux,when I update to node 7, this happened, "npm cache clean" does work.

In windows, npm cache clean also generate

Error: Cannot find module 'internal/fs'

Just remove

C:\Users[username]\AppData\Roaming\npm

C:\Users[username]\AppData\Roaming\npm-cache

solved

In my case clearing the cache did not work. Below was my initial state and how I resolved this:

node -v v7.4.0
npm -v 4.0.5

I resolved by doing the following and using n manager:

$ sudo n 6.9.1
$ sudo npm -g install npm@next
$ sudo n stable

Hope this helps!

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

The solution that worked for me was to

1) Delete node_modules/

sudo rm -R node_modules/ 

2) Re-run gulp

gulp

I'm on Windows 8.1 x64 , upgrading from v6 to v7. I got this issue on global installation I have many packages installed already, but every time I ran npm command, whether npm install, npm list,npm update etc. always return the same error

This step works for me:

  1. Clean npm cache manually by deleting npm-cache folder located at

C:\Users[usrname]\AppData\Roaming\

  1. Remove/rename npm folder in my NodeJS installation directory. In this case , I rename npm folder to npm-- in

C:\Program Files\nodejs\node_modules

  1. Re-install NodeJS v7

Everything works fine then

You need to install the last version of bower

> npm install -g bower

Apparently, npm > 4.0 do not use internal/fs module.

In my case clearing the cache did not work. What did work was deleting the node_modules/npm folder within my nodejs install location. Then running the nodejs installer again and using the 'repair' option (note: this is for Windows).

From what I could gather in the npm debug log, it looked like my old version of npm wasn't completely removed before the new version was installed. So there were some lingering deprecated modules in the folder where npm was installed.

If using mac

cd ~/.nvm/versions

and remove node folder

I solve this by installing NVM to manage Node

https://github.com/creationix/nvm#installation

after install NVM, reinstall node

nvm install node

On Win10 this worked for me: (adjust to relevant node version and username)

  • Uninstall node (via node-v7.8.0-x64.msi)
  • Remove the folders 'npm' and 'npm-cache' in 'C:\Users\yourusername\AppData\Roaming
  • Install node again (via node-v7.8.0-x64.msi)

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

None of the answers worked for me.

In the end I reinstalled node and ionic and that did the trick:

npm cache clean -f
npm install npm -g

npm uninstall node
npm install node -g

My system information before fixing the issue:

Cordova CLI: 7.0.1
Ionic CLI Version: 1.7.11         <-- way too old
Ionic App Lib Version: 0.6.5
ios-deploy version: 1.9.1
ios-sim version: 5.0.4
OS: Mac OS X El Capitan
Node Version: v8.0.0
Xcode version: Xcode 8.3.3 Build version 8E3004b

if you are using n to update node versions and all npm commands are failing with this message that means you have latest node but an older npm version.

so in this case do the following, (may need sudo)

n 4.7 npm install npm -g n latest

it will go back to node 4.7 and then install latest npm using it. after than it will come back to latest npm version. (replace latest with whatever version you actually want)

1) sudo npm cache clean -f

2) sudo npm install -g n

3) sudo n stable

Just Three Steps :)

Run

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

Again npm install. It will Works

本文标签: javascriptCannot find module 39internalfs39 after upgrading to node 7Stack Overflow