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.
Related
when I run the command to build the react-native library:
yarn prepare
show error:
yarn run v1.22.19
$ bob build
ℹ Building target commonjs
ℹ Cleaning up previous build at lib/commonjs
ℹ Compiling 1 files in src with babel
bob build
build files for publishing
Options:
--help Show help [boolean]
--version Show version number [boolean]
Error: [BABEL]: Cannot find module './built-in-definitions'
Require stack:
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/babel-plugin-polyfill-corejs2/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/preset-env/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/config/files/module-types.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/config/files/configuration.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/config/files/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/utils/compile.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/targets/commonjs.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/bin/bob (While processing: /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/preset-env/lib/index.js)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/babel-plugin-polyfill-corejs2/lib/index.js:8:27)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/preset-env/lib/index.js:32:34)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/babel-plugin-polyfill-corejs2/lib/index.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/preset-env/lib/index.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/config/files/module-types.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/config/files/configuration.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/config/files/index.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/#babel/core/lib/index.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/utils/compile.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/targets/commonjs.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/index.js',
'/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/bin/bob'
]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
why did this error happen? what should I do to fix this problem? I have already tried to remove node-module and yarn.lock. Also when create new project still happening and I try to update react-native-builder-bob.
Did you follow the 'Automatic configuration' or 'Manual configuration' steps as described in the documentation? https://github.com/callstack/react-native-builder-bob#automatic-configuration
It seems like Babel is not configured correctly. It can not find the built-in-definitions.ts file from the babel-polyfills package, which can be found here. https://github.com/babel/babel-polyfills/tree/main/packages/babel-plugin-polyfill-corejs2/src
I think Babel will be set-up correctly after finishing the configuration steps.
Edit:
Or did you configure your package using the commonjs build-target during setup? If you want to build a react-native package you should choose the module option. commonjs is used for Node environments, and React-native uses Metro.
I have installed selenium-webdriver globally using nmp install -g.
I have also made sure that path to the global node_modules is present in the NODE_PATH environment variable.
However when I try to execute a simple .js script, node fails to find the nodule.
I feel I'm missing something rather simple here, but can't figure out what.
ip-192-168-4-31:end2endtests xxxxx$ npm ls -g|grep "selenium.*"
└─┬ selenium-webdriver#4.0.0-alpha.1
ip-192-168-4-31:end2endtests xxxxx$ echo $NODE_PATH
/usr/local/lib/node_modules
ip-192-168-4-31:end2endtests xxxxx$ node tests.js
module.js:557
throw err;
^
Error: Cannot find module 'selenium-webdriver'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/xxxxx/Documents/end2endtests/helpers.js:1:79)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
I installed node-opencv for win10 x64. But when I run my app included opencv get an error.
>node app.js
module.js:434
return process.dlopen(module, path._makeLong(filename));
^
Error: The specified module could not be found.
\\?\C:\Users\...\node_modules\opencv\build\opencv\v6.0.0\Release\node-v46-win32-x64\opencv.node
at Error (native)
at Object.Module._extensions..node (module.js:434:18)
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)
at Object.<anonymous> (C:\Users\...\node_modules\opencv\lib\bindings.js:4:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)`
I tried to start "cmd" as a root. After that the error is gone. But I want to deploy my project on a hosting and anyone won't give me administrative privileges... So I need a tip that let me start app as simple user.
I'm running node v4.8.3, NPM 4.5.0.
This means that the DLLs can not be opened. You either don't have the opencv binaries dir in your system path or the DLLs do not match the .lib or .so files that you linked against.
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 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.