I have a .npmrc file with:
runtime = electron
target = 1.7.9
target_arch = x64
disturl = https://atom.io/download/atom-shell
build_from_source = true
And apackage.json file with:
"scripts": {
"start": "electron .",
"test": "mocha"
}
Following a npm install, when I run my node.js script using npm start, everything works as expected. However, when I use npm test I'm running into an error:
Uncaught LevelUPError: Failed to require LevelDOWN (The module '/Users/_me_/_project_/node_modules/leveldown/build/Release/leveldown.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 54. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using 'npm rebuild' or 'npm install').). Try 'npm install leveldown' if it's missing
My test.js file uses a small subset of modules that do not require electron.
I've tried running npm rebuild, npm install, and npm install leveldown after clearing the npm_modules directory, but the error persists.
Any idea why I'm seeing these errors or how to correct this issue?
Edit: I was able to switch mocha out with electron-mocha and bypass the error.
npm cache clean
npm install
electron-rebuild(need npm install electron-rebuild)
i ues these methods to solve the problem
Related
Symptom:
I can't execute the npm packages directly that are not installed globally. But I can execute it by npm scripts. How to fix it?
For example:
I installed gulp under the project:
npm install gulp --save-dev
Then I try to execute it by
gulp
zsh: command not found: gulp
But if I add a npm script to package.json:
"scripts": {
"test": "mocha --require intelli-espower-loader && gulp test",
"start": "gulp"
},
Then run
npm start
It can get executed without problem.
P.S.
Same issue with the mocha package, I can't execute mocha directly but I can execute npm test without problem.
Help Wanted:
What I can do to fix that issue?
Notice:
I'm not saying that I want to execute them globally, I just want to execute them under the project.
I don't know where goes wrong, but they are executable not long ago, just don't work recently!
In addition to #Ion's answer: You might need to add the path to the environment variables. In windows OS, it would be %AppData%\npm. For packages installed locally, you should be able to run them like
.\node_modules\.bin\gulp
If you want to execute them globally install with the -g flag
npm install gulp -g
To run directly you could also do ./node_modules/.bin/gulp
That is because the package not installed globally doesn't create a reference in the root node_modules folder . If you want to specifically use the local installed version to run globally on terminal then go to you environment variables and set the path to ./node_modules/gulp/bin/gulp.js or alternatively configure your npm to use the mentioned location as the gulp and execute node_modules/.bin/gulp
You have two choices:
Install the executable modules globally:
npm install -g gulp
This is good if it's a tool you use often (for many different projects). For gulp specifically, the globally installed gulp will also check to see if the project has its own gulp installed (in node_modules) and run that version of gulp. This means that each project can have its own version of gulp. But not all tools have this feature.
Use npx:
npx gulp
Newer versions of npm ships with a command called npx which will search through your project's node_modules directory to find a module to execute. This means you don't need to install project specific tools globally. Apart form avoiding global installs of commands (which may or may not be a security issue) it also allows you to install project specific versions of tools.
If your npm installation does not have npx you can install it from npm itself:
npm install -g npx
When I try to build my applicaton using electron it crashes on leveldown library
Error: The module '/Users/macosx/Documents/Electron/node_modules/leveldown/build/Release/leveldown.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 67. Please try re-compiling or re-installing
I have tried
rm -rf node_modules/leveldown
npm install
npm rebuild leveldown--update-binary
npm uninstall leveldown
Also tried this
I had the same problem and nothing mentioned here worked for me. Here is what >worked for me:
Require all dependencies you need in the main.js file that is run by
electron. (this seemed to be the first important part for me) Run npm
i -D electron-rebuild to add the electron-rebuild package Remove the
node-modules folder, as well as the packages-lock.json file. Run npm i
to install all modules. Run ./node_modules/.bin/electron-rebuild to
rebuild everything It is very important to run
./node_modules/.bin/electron-rebuild directly after npm i otherwise it
did not work on my mac.
I struggled with this for a couple days. The trick is to use electron-rebuild to build the native node module, and to include the option node.__dirname = true in your webpack config, as the leveldown bindings.js depend on the __dirname global provided by Node.
I am new to Angular2 and trying to setup the environment with the boilerplate code https://github.com/mschwarzmueller/angular-2-beta-boilerplate.
My dependencies installed fine with npm install but when I run npm start I start to get the below statements. I don't think its an error but its hard to figure out as to what it really means.
$ npm start
> angular2-boilerplate#1.0.0 start C:\Users\user\desktop\angboiler\angular-2-beta-boilerplate
> concurrent "npm run gulp" "npm run lite"
I tried installing run lite, concurrently separately but that didn't work. I even ran npm update -g && npm install -g concurrently lite-server typescript
to make sure i have stuffs updated to make it work but still no progress.
I have: typescript 1.8 version node 4.4.5 version running.
Alternatively, perhaps you would be interested in using Angular CLI, which seems to be the official boilerplate for Angular 2.
Weird behaviour on my OSX Yosemite: from one day to another all my node modules installed by npm install -g were not found via the Terminal.
I'm not sure if this is due to my node v4.0.0 install the day before.
Try this
echo $(npm config get prefix)/bin
you will get STRING, which should include to your .bash_profile such way
export PATH=$PATH:STRING
Install it globally
npm i -g webpack
If you will work with webpack, install webpack-dev-server too
npm i -g webpack-dev-server
After I Install this two command I also found errors when run the
webpack
command so I figure out the problem by changing the version of webpack so I Install
npm install webpack#2.1.0-beta.22
and every thing work fine for me.
I recommend you first learn a bit about npm and then webpack. You will struggle a lot. but finally you will find the right destination.
I've finally also used NVM for multiple NodeJS versions management and everything went back under control.
Webpack is in your ./node_modules/.bin/ folder so instead of giving just webpack as the command try this.
./node_modules/.bin/webpack
You have the npm bin command to get the folder where npm will install
executables.
You can use the scripts property of your package.json to use webpack
from this directory which will be exported.
"scripts": { "scriptName": "webpack --config etc..." } For example:
"scripts": { "build": "webpack --config webpack.config.js" } You can
then run it with:
npm run build Or even with arguments:
npm run build -- <args>
This allow you to have you webpack.config.js in the root folder of
your project without having webpack globally installed or having your
webpack configuration in the node_modules folder.
My task is to build a HTML5 desktop app, which works with serial port, because I have an arduino on the other side on COM-port.
I installed electron-prebuilt and serialport packages both (I specified them in package.json).
In my main web page I included main.js, and there I tried to require the serialport package, but I got the following error:
Uncaught Error: Cannot find module
'D:\Projects\arduino\HTMLPresentation\node_modules\serialport\build\serialport\v1.7.4\Release\node-v45-win32-x64\serialport.node'
I've read some QA topics about that problem (some abracadabras with node-gyp), but noting works for me: on both windows 8.1 and Ubuntu 15.04. I don't know how to adopt serialport package for electron.
My enviroment:
Vue.js: 2.6.10
Electron: 2.0.18
Node: 8.9.3
Platform: linux
If you are using Eletron with Vue.js you need to rebuild the serialport module doing something like this:
npm install electron-rebuild --save-dev
after this, you can add in your package.json > section "scripts", another line saying:
"rebuild": "electron-rebuild -f -w serialport"
You can rebuild the module with terminal command
npm run rebuild
Now the serialport module should be imported and will work as expected. Goog luck!
Use Electron-Rebuild: This executable rebuilds native io.js modules against the version of io.js that your Electron project is using. This allows you to use native io.js modules in Electron apps without your system version of io.js matching exactly.
npm install --save-dev electron-rebuild
# Every time you run "npm install", run this
./node_modules/.bin/electron-rebuild
# On Windows if you have trouble, try:
.\node_modules\.bin\electron-rebuild.cmd
This is how you would solve it
Install windows build tools in your computer by running this in your powershell with administrator access
npm install --global --production windows-build-tools
or npm --add-python-to-path='true' --debug install --global windows-build-tools
setx PYTHON "%USERPROFILE%\.windows-build-tools/python27/python.exe"
set PYTHON
set PYTHON helps you check if its set up correctly.
This is not enough install electron rebuild globally in your project files
npm install -g electron-prebuilt
npm install --save serialport
We have to rebuild serialport to work with electron. To do this, we need to >install electron-rebuild:
npm install --save-dev electron-rebuild
The last step is to run electron-rebuild, once again, just in the root >directory of the app:
./node_modules/.bin/electron-rebuild
import and use in your electron-vue project
<script>
const sp = require('serialport')
export default {
name: 'landing-page',
methods: {},
created () {
sp.list(function (error, ports) {
if (error) {
console.log(error)
} else {
console.log(ports)
}
})
}
}
</script>