"cannot find module" when installing npm modules on windows - windows

I am new to NodeJS. I am trying to use npm on Windows 8.
I have installed using chocolatey, cinst nodejs.install (version 0.10.17). I installed as administrator (and would prefer to run npm as a normal user).
Node itself seems to be working, I can use the REPL to run simple programs.
If I try to install something using npm, I get cannot find module:
> node npm install express
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\Klas\Documents\My Dropbox\mina egna\tech\node\webserver\npm'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
I have read the answers on Nodejs cannot find installed module on Windows? but unfortunately it is still unclear to me what I have to do.
I have tried setting NODE_PATH:
In trying to follow this answer, I have tried setting it to C:\Users\Klas\AppData\Roaming\npm\node_modules (but I had to create both the npm and the subfolder node_modules myself)
I have tried creating a folder c:\node\node_module (according to this advice, even though the installation did not even create a c:\node folder) and setting it to that.
I have tried setting it to C:\Program Files\nodejs\node_modules\npm\node_modules (which did exist after installation)
I have also tried to create a node_modules folder below the current working directory. As I understand it that is where local npm will be installed?
None of these helped. So it seems to me that setting NODE_PATH is not the solution?
Using the -g flag makes no difference (I would prefer not to use it).
I get the same error both as normal user and as administrator (I would prefer to be a normal user).
I get the same error no matter where I execute the command, except when I do it in C:\Program Files\nodejs, where I get
basedir=`dirname "$0"`
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)

Not using windows, but I'm pretty sure it's just npm install express on windows too.

Related

Can't properly install hardhat using Powershell! Persistent Error HH12: Trying to use a non-local installation of Hardhat, which is not supported

Below is a short list of my setup until I stumble upon the HH12 Hardhat Error that I keep getting:
mkdir wave (Name of my directory)
cd wave
npm init -y
npm install —save-dev hardhat
npx hardhat
Choose sample project
6a. Hardhat project root (Select)
6b. Add .gitignore
Say yes to everything
install the remaining dependencies: npm install --save-dev #nomiclabs/hardhat-waffle ethereum-waffle chai #nomiclabs/hardhat-ethers ethers
npx hardhat accounts (to see all the different accounts)...
...And then it fails here! An HH12 Hardhat Error Message: "Hardhat is not installed or installed globally. You tried to run Hardhat from a global installation or not installing it at all. This is not supported. Please install Hardhat locally using npm or Yarn, and try again." (https://hardhat.org/errors/) [BTW, these 2 lines are the ONLY docs on this error on Hardhat!].
Any suggestions?
I have tried the following possible 'fixes' to sidestep this error but to no avail:
Updating most current version of node
Restarting my PC (About 17 X now as of this writing)
Using GitBash (Instead of Powershell)
Asking mods in Hardhat Discord (None) and other Discords
Opening the Hardhat docs (And the Tutorials!!) for answers... None!
StackExchange - There's literally only 1 other person who ALSO had this problem here! But the answers here are not the solution. (Have DMd that person but no reply as of yet).
So can anyone out there help?
I believe I finally figured out the solution (at least what worked for me):
I dropped back 2 directory levels from where I was for my root project and started again there.
I updated my Node version to 16.

Yarn.cmd vs Yarn

for the past 3 weeks yarn has worked just fine. Now randomly i can't use yarn anymore unless I use yarn.cmd start. Why does yarn require the ".cmd" all of a sudden.
If i use the normal yarn commands i get the following error:
$ yarn
module.js:549
throw err;
Error: Cannot find module 'C:\Users\Me\Desktop\CodeProject\material\client\yarn.js
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at boostrap_node.js:612:3
You are running with bash on Windows. You have another copy of yarn in your PATH, one with .cmd as extension and one with another extension. To find the offending copy of yarn, do:
$ which yarn
It depends on what you find but you're probably uninstalling something or changing your PATH environment variable.

Your JET project does not have oraclejet-tooling installed

I recently installed Oracle jet and I haven't made any changes to it. I created my first project today and it's showing error when I try to build it or serve it. I am trying to run it on Visual Studio (I don't this matters tho)
This is the error I am getting
PM> ojet serve ojet : [31mError: Your JET project does not have oraclejet-tooling installed.[0m
At line:1 char:
+ ojet serve
+ ~~~~~~~~~~
+ CategoryInfo : NotSpecified: ([31mError: You... installed.[0m:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
UPDATE: Apparently when I create a new template it is creating an error from there itself the app structure is generated but during invoking mom install it is unable to parse through some certain JSON
Following is the Error:
ojet create ojetnavbar --template=navbar
Processing template: navbar
Your app structure is generated. Continuing with library install.
Performing npm install may take a bit.
Invoking npm install.
npm WARN deprecated coffee-script#1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm ERR! Unexpected end of JSON input while parsing near '...oIzTWjIvO8rspcLCK+1pI'
npm ERR! A complete log of this run can be found in:
npm ERR! *location of log*
Error: (during Invoking npm install.) 1
$ npm install -g #oracle/ojet-cli
$ npm install -g #oracle/oraclejet-tooling
$ ojet restore
This will solve your problem
I have sorted out on the issue it was because the JSON npm was trying to parse were mostly cached and due to that a parsing error was occurring
I used npm-cache clean on my PC and all of it ran after that perfectly fine.
I think you need to add oraclejet tooling to your project. Try this:
cd appDir
npm install #oracle/oraclejet-tooling --save
oraclejet-tooling package has been deprecated, you have to use module contains a command-line interface for Oracle JET web and hybrid mobile application development.
See https://www.npmjs.com/package/#oracle/ojet-cli
cd oracle-jet-simple-web
npm install #oracle/ojet-cli --save
For me this helped
npm i #oracle/oraclejet-tooling
Here is the link: npmjs.com/package/#oracle/oraclejet-tooling

Running Processing sketches in the Atom editor

I am trying to use the Atom text editor for Processing development in Windows, and am having some issues. Internet restrictions at work mean I cannot use the built-in package manager within Atom:
Fetching featured packages failed: connect ECONNREFUSED
Therefore, I need to install packages manually. I am trying to use bleikamp's Processing package for atom which allows the running of processing sketches, and have unzipped the package, downloaded from github, in the packages folder - C:\Users\my_username\.atom\packages.
The package is detected within Atom as being installed, but when I try and run a sketch, the below error occurs:
Failed to activate the processing package
Cannot find module 'ps-tree'
Error: Cannot find module 'ps-tree'
at Module._resolveFilename (module.js:455:15)
at Module._resolveFilename (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\electron.asar\common\reset-search-paths.js:35:12)
at Function.Module._resolveFilename (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\module-cache.js:383:52)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\native-compile-cache.js:50:27)
at Object.<anonymous> (file:///C:/Users/chris.hamilton/.atom/packages/processing-master/lib/processing.coffee:4:10)
at Object.<anonymous> (file:///C:/Users/chris.hamilton/.atom/packages/processing-master/lib/processing.coffee:1:1)
at Module._compile (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\native-compile-cache.js:109:30)
at Object.value [as .coffee] (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\compile-cache.js:216:21)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\native-compile-cache.js:50:27)
at Package.module.exports.Package.requireMainModule (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\package.js:796:27)
at Package.module.exports.Package.activateNow (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\package.js:207:16)
at C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\package.js:876:25
at Function.module.exports.Emitter.simpleDispatch (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\event-kit\lib\emitter.js:25:14)
at Emitter.module.exports.Emitter.emit (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\event-kit\lib\emitter.js:129:28)
at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\command-registry.js:240:20)
at C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\command-registry.js:3:59
at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\atom-keymap\lib\keymap-manager.js:599:16)
at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\node_modules\atom-keymap\lib\keymap-manager.js:390:22)
at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\window-event-handler.js:106:36)
at HTMLDocument.<anonymous> (C:\Users\chris.hamilton\AppData\Local\atom\app-1.14.4\resources\app.asar\src\window-event-handler.js:3:59)
I assume this is an issue with dependencies and I am probably missing a step in manually installing the package - can anyone offer any guidance? I have researched fairly extensively into manually installing packages, and there is a lot of information about using commands such as apm link and apm install, but I can't seem to access these commands.
EDIT: I have included processing-java in my PATH variable. Below is the output when path is called from cmd:
PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\ProgramData\Oracle\Java\javapath;C:\WIN
DOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPow
erShell\v1.0\;C:\Program Files (x86)\Microsoft Office\Office14\;C:\Program Files
(x86)\Enterprise Vault\EVClient\;C:\Program Files\Hummingbird\Connectivity\14.0
0\NFS Maestro\;C:\Program Files (x86)\Hummingbird\Connectivity\14.00\NFS Maestro
\;C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v713\runtime\win32;C:\WI
NDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Sh
ared\;C:\Program Files\MATLAB\MATLAB Runtime\v90\runtime\win64;C:\Program Files\
TortoiseSVN\bin;C:\ChrisHamilton\Room_Results_Comparison\processing-3.2.1\;C:\Us
ers\chris.hamilton\AppData\Local\atom\bin
Any help would be much appreciated.
As you have guessed already, missing package dependencies are causing this error. Since you don't seem to have internet connection (or limited connection) at work, I'd recommend installing the Processing package where you are online (e.g. at home), then compress the processing folder and extract it inside the Atom packages folder at work. Make sure the processing folder includes node_modules. Optionally repeat those steps for the script package.
Dependencies are installed running apm install (or npm install) inside the package folder. Whenever an Atom package has dependencies, this step is essential. Atom (or apm) are doing this automatically.
To give you some more insights into the process, here's an alternative way to install a package with dependencies:
cd %USERPROFILE%.atom\packages
git clone https://github.com/bleikamp/processing
cd processing
npm install
It looks like you're running Windows and processing-java hasn't been added to your PATH. Try the following:
Open Advanced System Settings either by running sysdm.cpl or searching in Control Panel.
Click the Environment Variable button on the Advanced tab.
Edit the PATH variable to include the Processing directory (e.g. C:\Program Files\Processing-3.1.1\) in either the User variables (for just your account) or System variables (for all users).
Also note that bleikamp no longer maintains his Processing package and instead recommends using Script.

Working with compound js on windows. Cannot start anything

I wish to create a hello world application using compound.js.
So far, nothing works at all.
I've installed "npm install compound -g" to have compound be available globally.
Now I wish to run "compound init" and I get this:
(see first code block)
While googling, I found an example app on npm called mongoose-compound-example-app.
After npm installing that, I ran "node ." as suggested in the readme:
(see second code block)
I am using Windows 8 x64. Node itself works, and I've been able to run a "hello world" application using locomotive.js. I really want to get compound figured out and working, but I can't seem to get anywhere at all.
Thank you in advance!
EDIT:
I am using Node v0.10.0
C:\Users\Lev\test>compound init hello
path.js:204
throw new TypeError('Arguments to path.join must be strings');
^
TypeError: Arguments to path.join must be strings
at f (path.js:204:15)
at Object.filter (native)
at Object.exports.join (path.js:209:40)
at CompoundServer.module.exports [as extensions] (C:\Users\Lev\AppData\Roaming\npm\node_modules\compound\lib\server\extensions.js:13:25)
at CompoundServer.initCompound (C:\Users\Lev\AppData\Roaming\npm\node_modules\compound\lib\compound.js:100:14)
at CompoundServer.init (C:\Users\Lev\AppData\Roaming\npm\node_modules\compound\lib\server\compound.js:42:29)
at C:\Users\Lev\AppData\Roaming\npm\node_modules\compound\lib\compound.js:61:18
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:903:3
mongoose-compound-example-app error:
C:\Projects\mongoose-compound-example-app\config\environment.js:11
app.use(compound.assetsCompiler.init());
^
TypeError: Cannot call method 'init' of undefined
at Function.<anonymous> (C:\Projects\mongoose-compound-example-app\config\environment.js:11:41)
at Function.app.configure (C:\Projects\mongoose-compound-example-app\node_modules\express\lib\application.js:396:61)
at module.exports (C:\Projects\mongoose-compound-example-app\config\environment.js:10:9)
at evalInContextOf (C:\Projects\mongoose-compound-example-app\node_modules\compound\lib\compound.js:187:9)
at requireIfExists (C:\Projects\mongoose-compound-example-app\node_modules\compound\lib\compound.js:165:9)
at configureApp (C:\Projects\mongoose-compound-example-app\node_modules\compound\lib\compound.js:147:5)
at CompoundServer.initCompound (C:\Projects\mongoose-compound-example-app\node_modules\compound\lib\compound.js:91:9)
at CompoundServer.init (C:\Projects\mongoose-compound-example-app\node_modules\compound\lib\server\compound.js:42:29)
at C:\Projects\mongoose-compound-example-app\node_modules\compound\lib\compound.js:61:18
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:903:3
As discussed in the chat, there seems to be a problem or conflict with the version of Node.js you are using.
Compound's package.json says that it expects Node.js 0.8.0 or higher. You mentioned that it works in 0.9, but not in 0.10. This is likely a bug, as the odd-numbered versions of Node are typically the unstable versions before the later even number stable releases.
I recommend posting a reproducible example on the bug tracker for Compound, and possibly Node.js if you can narrow it down to a Node issue.

Resources