I have a freshly installed Ubuntu 22.04.1 LTS on which I have installed npm and docker.
When I want to start my NextJS web server (npm run dev) and the following error message appears:
niklas#srv-code01:~/Desktop/Code/Javascript/NextJS/website_01$ npm run dev
> website_01#0.1.0 dev
> next dev
/home/niklas/Desktop/Code/Javascript/NextJS/website_01/node_modules/next/dist/cli/next-dev.js:315
showAll: args["--show-all"] ?? false,
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.dev (/home/niklas/Desktop/Code/Javascript/NextJS/website_01/node_modules/next/dist/lib/commands.js:10:30)
at Object.<anonymous> (/home/niklas/Desktop/Code/Javascript/NextJS/website_01/node_modules/next/dist/bin/next:141:28)
at Module._compile (internal/modules/cjs/loader.js:999:30)
I can't see anything from the error message. What is the reason for the error? The error message also occurs with the following command: npm run start
I have the latest version of NPM installed.
Start of the NPM Development or Production Server on Port 3000
I had the same error and to resolve that I used the node version manager(nvm) to update my node.js version to 18.12.1.
To fix this, you need to follow the steps in this order-
Run this command to get the nvm.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Restart your terminal.
Install nvm- nvm install v18.12.1
Start nvm- npm run dev
You can use nvm list-remote to look at a complete list of the versions to choose from.
For more information, read here under option 3-
installing-node-using-the-node-version-manager
You can try init project by npx create-next-app#latest, not npx create-next-app. It works for me. Good luck~
Related
I an a Windows 10 user who uses WSL. I was using Ubuntu 20.04.5 provided from the Microsoft Store and executing node commands with no issues. However, I attempted to update Ubuntu 20.04.5 to Ubuntu Jammy (22.x) and I found that it was generating some errors when I attempted to utilize nodejs after installing nodejs and npm.
I decided to go back to using Ubuntu 20.04.5, and after reinstalling nodejs and npm I am encountering the same issues I had on Jammy. When I try to run my plain JavaScript app using node, I am greeted with the following error.
So far, I have found nothing that has solved my problem.
I also tried restarting the terminal as well as my computer. I am continually met with an error indicating that it cannot find the modules I am looking for. Please note that I have not used yarn or curl for any downloads, and have only used apt install as well as npm install.
When I attempt to run my app.js file in the correct directory.
>> node app.js
noseinternal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'stream/promises'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/mnt/c/Users/.../group-project-1-group-6-15064/lib/weatherHandler.js:4:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
So far, the error seems to make sense. Even though I have a node_modules folder in the directory, it may not have the specific module it is trying to load.
So I then try to use the node install command to install all dependencies based on my package.json.
>> node install
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/mnt/c/Users/.../group-project-1-group-6-15064/install'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
This command worked perfectly before I reinstalled everything.
I also tried to add to the PATH in my .bashrc file to no avail. I'm sure it's something so simple and frustrating, but after over 30 hours of troubleshooting, I have yet to have any kind of breakthrough.
Possibly useful info:
>> which node
/usr/bin/node
>> node -v
V10.19.0
>> which npm
/usr/bin/npm
>> npm -v
6.14.4
>> sudo npm install --global --verbose nodejs
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli '/usr/bin/npm',
npm verb cli 'install',
npm verb cli '--global',
npm verb cli '--verbose',
npm verb cli 'nodejs' ]
npm info using npm#6.14.4
npm info using node#v10.19.0
...
npm verb unbuild rmStuff nodejs#0.0.0 from /usr/local/lib/node_modules
...
npm verb exit [ 0, true ]
stream/promises was added in Node 15: https://nodejs.org/api/stream.html#streams-promises-api.
You have to update your Node.js, for that please refer to: https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
You may use nvm to install and manage Node versions
# Download curl CLI utility
sudo apt-get install curl
# download nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
command -v nvm
If that doesn't work refer to nvm's troubleshooting guide.
Once you setup nvm, you can run
nvm install 16 # For example to install Node.js v16
nvm use 16 # To enable it in your current terminal
After that, you may need to reinstall your packages to avoid any unwanted behavior, just delete node_modules in your current project and re-run npm install.
I am facing errors with grunt commands for a dojo project with following version of node, npm and grunt-cli
grunt-cli version : 0.1.13
node version : 6.17.1
npm version : 3.10.10
Getting below error when running grunt command after npm install.
PS C:\workspace\ui\test\ui> grunt
module.js:478
throw err;
^
Error: Cannot find module 'has'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\6110853\AppData\Roaming\nvm\v6.17.1\node_modules\grunt-cli\node_modules\is-core-module\index.js:3:11)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
Tried npm install after deleting node_modules.
Tried installing has module before running npm-install
grunt-cli has been installed globally and I see the required module is present in node_module but we still get module not found error.
Can anybody suggest how to resolve this issue ?
This may be caused by incompatible dependencies. I encountered the same error on grunt#1.3.0. Upgrading node/npm tools to newer versions solved the problem in my case:
node#6.3.1 -> node#12.14.0
npm#3.10.3 -> npm#6.13.4
I am trying to login on facebook.com with selenium-webdriver.
var webdriver = require('selenium-webdriver'),
By = require('selenium-webdriver').By,
until = require('selenium-webdriver').until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('https://www.facebook.com/login');
driver.findElement(By.id('email')).sendKeys('****');
driver.findElement(By.id('pass')).sendKeys('*****');
driver.findElement(By.id('loginbutton')).click();
driver.findElement(By.linkText('Settings')).then(function(element) {
console.log('Yes, found the element');
}, function(error) {
console.log('The element was not found, as expected');
});
driver.quit();
It is giving error:
/home/shubham/node_modules/selenium-webdriver/index.js:25
const builder = require('./builder');
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
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> (/home/shubham/Music/amazon_login/test_22_4_16/sel_login.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
node --version v0.10.37
npm --version1.4.28
protractor --version Version 3.2.2
selenium-webdriver#2.53.1
Updating nodejs solved the issue:
npm cache clean -f
sudo npm install -g n
sudo n stable
node --version
node app.js
You have to run the second and third command as root/administrator.
n stable wouldn't do the trick for me. On the other hand,
nvm install stable
That actually got me to last nodejs version. Apparently n stable won't get pass v0.12.14 for me. I really don't know why.
Note: nvm is Node Version Manager, you can install it from its github page. Thanks #isaiah for noting that nvm is not a known command.
For me it was more simple to solve, just going to the Node web site, get and install the LTS version.
Update your node and it will resolve this problem.
Updating NodeJS solves this problem.
But, after running sudo npm install -g n you might get following error:
npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference
In order to overcome this error, try upgrading openssl using the below command:
sudo yum update openssl
That error means your node's publish is low than the need.
carefully to update the node of your computer.
Been trying to install nodemon globally and although installed, I got a permission error when trying to run nodemon app.js in my terminal (using zsh). The following error:
/usr/local/lib/node_modules/nodemon/node_modules/configstore/index.js:53
throw err;
^
Error: EACCES: permission denied, open '/Users/carlosgrijalva/.config/configstore/update-notifier-nodemon.json'
You don't have access to this file.
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at Object.get (/usr/local/lib/node_modules/nodemon/node_modules/configstore/index.js:34:26)
at Object.Configstore (/usr/local/lib/node_modules/nodemon/node_modules/configstore/index.js:27:44)
at new UpdateNotifier (/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/index.js:34:17)
at module.exports (/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/index.js:123:23)
at Object.<anonymous> (/usr/local/lib/node_modules/nodemon/bin/nodemon.js:15:27)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
I found this article: https://docs.npmjs.com/getting-started/fixing-npm-permissions
And followed the instructions in option 1 by running the following command:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
I'm debating reinstalling node and since i'm using 6.11 and figured I might as well use the latest version but I'm unsure if that's the wisest move at this point. If anyone has any other suggestions I'd really appreciate it.
I installed "electron-packager" using npm and executed the command
electron-packager . Johnston --platform=darwin --arch=x64 --version=0.36.0
And then I when I run the "Johnston.app", this error showed up (I didn't even see the main window)
Uncaught Exception: Error: Cannot find module 'electron'
at Function.Module._resolveFilename (module.js:332:15)
at Function.Module._load (module.js:282:25)
at Module.require (module.js:361:17)
at require (module.js:380:17)
at Object. (/Users/David/Github/Johnston/Johnston-darwin-x64/Johnston.app/Contents/Resources/app/main.js:3:18)
at Module._compile (module.js:426:26)
at Object.Module._extensions..js (module.js:444:10)
at Module.load (module.js:351:32)
at Function.Module._load (module.js:306:12)
at Object. (/Users/David/Github/Johnston/Johnston-darwin-x64/Johnston.app/Contents/Resources/atom.asar/browser/lib/init.js:104:10)
Is there any solutions? Thanks!
This likely has something to do with you having a different version of Electron installed on your machine that you are using to build with. In the folder for your app, run electron --version to get the version of electron that you have installed. Then, change the --version=0.36.0 to use whatever version you have installed.
If that doesn't fix it, then you should try rm -rf node_modules && npm install on your project. This will remove you node modules and then reinstall them all. If that doesn't work, please comment here and I will try to help again.