I am trying to run a sails application with Webstorm 7.0.3.
this appear when i try to run the server in the console log:
module.js:340
throw err;
^
Error: Cannot find module 'sails'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:\Users**\projects\WebstormProjects**\app.js:2:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain [as _onTimeout] (module.js:497:10)
Process finished with exit code 8
i installed sails globaly. i know that this is dont work because it cant find the sails module in the project's local 'node_modules' directory. if ill install again 'sails' localy it will work. but i dont want to...
Is there a way to make it work with sails global install? thanks!
The sails module that your code is looking for is not the same thing as the sails command you're executing at the terminal.
The command generates project skeletons. The module is the code that actually makes it run.
You need to install the command globally and the module locally.
Global installation (using npm install -g) does not make modules available globally to all node applications, it's only there for command line stuff.
If your applications relies on Sails, you should have it in your dependencies in package.json as well as installed locally.
If you don't like the way that npm creates a copy of each module locally, use yarn and tell it to symlink the cached version.
Related
i've been trying to use Yeoman to scaffold a mean app with angular-fullstack-generator, however i've been encountering this weird error i'd never encountered before, i've already tried reinstalling grunt-cli, npm, yo, none of it works, i'm using NVM and Node 4.4.0
I have Python 2.7.11 installed, apparently the 32-bit version, whereas everything else is 64-bit, i don't know if this might be what's causing the problem.
The full description of the error as shown on the console is as follows:
yo angular-fullstack
module.js:327
throw err;
^
Error: Cannot find module 'babel-runtime/helpers/interop-require-default'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Jonny\AppData\Roaming\npm\node_modules\generator-angular-fullstack\node_modules\babel-register\lib\node.js:3:30)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
So, what am i doing wrong here? Is there anything else i can try to fix the problem?
The error occurs because the babel-runtime module is missing. The babel-runtime module is required for babel to work.
You can fix this by running the command:
npm install --save babel-runtime
I solved it uninstalling and removing babel from node global dependencies and then reinstalling yo and generatog-angular-fullstack.
I had a similar error, it couldn't find gulp-babel, so I installed the module globally.
$ npm install -g --save gulp-babel
And if you're using a mac you may want to try to put sudo in front of the command.
I'm trying to run some NodeJS code using Sharp and i'm getting the following error:
[root#localhost myapp-backend]# node server.js
module.js:340
throw err;
^
Error: Cannot find module './build/Release/sharp'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/root/myapp-backend/node_modules/sharp/index.js:11:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/root/myapp-backend/server.js:277:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:935:3
Any ideas?
Thank you.
Turns out the Debian 8.x distribution I used did not include vips but I did not get an error message. Running
apt-get install libvips
followed by
npm install sharp
resolved the problem and sharp is finally installed and working.
It's probably due to Sharp not getting installed. When I installed it via
npm, there were no errors, but when I went into node_modules/sharp, three were no build files.
You can try to build it by doing
node-gyp rebuild
But, before that, make sure you have Vips installed - that's a lib that Sharp uses. On Mac you'd do
brew install homebrew/science/vips --with-webp --with-graphicsmagick
After you build the Sharp library, you should be good to go.
Check if you don't have build folder on node_modules/sharp, then run:
npm i sharp
it will reinstall and builds sharp. (worked for me)
I was getting the same error in Lambda function for s3 image crop.
I installed the sharp module as below and I was able to crop images using Node.js 14.x version.
npm install --platform=linux --arch=x64 sharp
Please check "node_modules/sharp/build/Release/" folder for "sharp-linux-x64.node"
In my case installing the sharp for specific target version of node.js works, I used below command, but before that remove your existing node_modules folder or remove rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=16x sharp
What worked for me was updating to the latest Node 13 instead of the Node 8 that apt-get provides by default. Answering just for future reference.
My code was working previously before, but seems to have stopped working. I tried yo angular:route api but this error was returned:
Error: Cannot find module 'ansi-styles'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/usr/local/lib/node_modules/generator-angular/node_modules/chalk/index.js:2:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I have added all the dependencies required to my package file, update npm (which is now on 2.0.0alpha), all npm packages, and ran npm install. The site still works when I grunt serve.
(The O.P.):
I found the reason I got the error. I had to change the npm root folder and reinstalled my packages in the default folder and now it works.
Just needed to run npm install here. Was a fresh clone out of Git.
Installing the module globally working for me.
npm install ansi-styles -g
I want to use MEAN.io stack. I did the required initialization. Created the folder, did the npm install, got the libraries.
now in server/config/express.js I have
assetmanager = require('assetmanager'),
and
// Import your asset file
var assets = require('./assets.json');
assetmanager.init({ // this is line 75
js: assets.js,
css: assets.css,
debug: (process.env.NODE_ENV !== 'production'),
webroot: 'public/public'
});
and this gives me this error:
server/config/express.js:75
assetmanager.init({
^
TypeError: Object #<Object> has no method 'init'
at module.exports (server/config/express.js:75:18)
at module.exports (server/config/system/bootstrap.js:49:48)
at Object.<anonymous> (server.js:20:54)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
[nodemon] app crashed - waiting for file changes before starting...
I have the package installed.
npm info assetmanager version
0.1.3
The author mistakenly published an incompatible version of assetmanager. You can either use version v0.1.2 instead by running npm install assetmanager#0.1.2 command.
Or change your code to be compatible with the latest. Check the README for the example.
Farid is correct that assestmanager pushed out an incompatable version.
The mean.io project has since been updated to use the 0.1.2 version. Commit
All new mean.io projects will have the correct version.
For projects that do not work you can either change your package.json or manually run npm install assetmanager#0.1.2
Please note that it is recommended to rather update your package.json to prevent issues when you change environments or go to production.
I have a small node script named /tmp/test.js containing this:
console.log(require("w3cjs"));
If I do this from the command prompt:
nvm use v0.10.21
node /tmp/test.js
I get this output:
module.js:340
throw err;
^
Error: Cannot find module 'w3cjs'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/tmp/test.js:1:75)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
But if I do this:
node -e $(cat /tmp/test.js)
I get this output:
{ validate: [Function: validate],
setW3cCheckUrl: [Function: setW3cCheckUrl],
w3cjs: [Circular] }
(In other words - it works.)
Why the difference and how do I make the script work?
When you run a script in a different directory, Node looks for local modules in the node_modules folder of that script's directory.
Suppose your shell's working directory is currently /projects/foo. When you run node /tmp/test.js, Node looks for modules in /tmp/node_modules, not in /projects/foo/node_modules.
However, if you don't run a script file, but run some text on the command line with -e, Node will check for a local module folder in your shell's current working directory, i.e., /projects/foo/node_modules.
It appears that you have w3cjs installed in your working directory, but not at /tmp. You should either install it there, or install the module globally with npm's -g option.