I am following the tutorial located here: https://www.apollographql.com/docs/apollo-server/getting-started. I am trying to use the JavaScript code and am getting this syntax error:
import { ApolloServer } from '#apollo/server';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:703:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:826:10)
at internal/main/run_main_module.js:17:11
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! guide-graphql#1.0.0 start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the guide-graphql#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
I have tried other Node JS examples as well and am getting the same error. Below is the package.json as well. I am running npm start to execute. Any advice would be appreciated on fixing this syntax.
{
"name": "guide-graphql",
"version": "1.0.0",
"description": "Apollo GraphQL server for Guide",
"main": "app.js",
"type": "module",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"#apollo/server": "^4.3.2",
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"express": "^4.18.2",
"graphql": "^16.6.0"
}
}
Related
package.json
{
"name": "5ambot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^13.5.0",
"dotenv": "^10.0.0"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
when i run npm start i gett an error in internal/modules/cjs/loader.js:892
error
Error: Cannot find module 'node:events'
Require stack:
- DIR\node_modules\discord.js\src\client\BaseClient.js
- DIR\node_modules\discord.js\src\index.js
- DIR\index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (DIR\node_modules\discord.js\src\client\BaseClient.js:3:22)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'DIR\\node_modules\\discord.js\\src\\client\\BaseClient.js',
'DIR\\node_modules\\discord.js\\src\\index.js',
'DIR\\index.js'
]
}
i tried reinstalling package-lock:
-rm -rf node_modules package-lock.json && npm install && npm start
didn't work. I am out of ideas and everyone says its cuz the node version is too low and i saw no other solution. Please help
edit: i came to a conclusion that its the discord.js that isn't loading correctly with npm install discord.js
try
Delete node_modules
run
npm cache clean --force
npm install
npm run start
or try yarn
yarn
I am trying to deploy my first node application to production server in a shared hosting platform but whenever I run the start script I get the following error message:
returncode: 1 stdout:
thechoicebox-backend#1.0.0 dev /home/ftijpnql/tcb
node server.js --scripts-prepend-node-path stderr: npm WARN lifecycle The node binary used for scripts is
/home/ftijpnql/nodevenv/tcb/14/bin/node but npm is using
/opt/alt/alt-nodejs14/root/usr/bin/node itself. Use the
--scripts-prepend-node-path option to include the path for the node
binary npm was executed with. internal/modules/cjs/loader.js:905
throw err; ^
Error: Cannot find module
'/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node'
Require stack:
/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js
/home/ftijpnql/tcb/src/controller/admin-auth.controller.js
/home/ftijpnql/tcb/src/app.js
/home/ftijpnql/tcb/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object. (/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Module.require (internal/modules/cjs/loader.js:974:19) { code: 'MODULE_NOT_FOUND', requireStack: [
'/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js',
'/home/ftijpnql/tcb/src/controller/admin-auth.controller.js',
'/home/ftijpnql/tcb/src/app.js',
'/home/ftijpnql/tcb/server.js' ] } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! thechoicebox-backend#1.0.0 dev: node server.js --scripts-prepend-node-path npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the thechoicebox-backend#1.0.0 dev script. npm ERR! This is
probably not a problem with npm. There is likely additional logging
output above.
npm ERR! A complete log of this run can be found in: npm ERR!
/home/ftijpnql/.npm/_logs/2021-10-05T16_19_33_946Z-debug.log
Although with same dependency and node version the project is running in my system.
package.json
{
"name": "thechoicebox-backend",
"version": "1.0.0",
"engines": {
"node": "14.7.0"
},
"description": "",
"main": "index.js",
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"http": "0.0.1-security",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.2",
"mysql2": "^2.2.5",
"sequelize": "^6.6.2"
},
"devDependencies": {
"nodemon": "^2.0.7"
}
}
My production node version is 14.x.x not same as in package.json file as that was not present there.
Kindly help me out I am stuck !
I had a "similar" problem with Node when I was debugging and I wanted to change to dev using nodemon.
Check your /dist folder
The /dist folder contains the minimized version of the source code.
The code present in the /dist folder is actually the code which is used on production web applications. Along with the minified code.
The /dist folder also comprises of all the compiled modules that may or may not be used with other systems.
The /dist folder also contains all those files which are required to run/build a module for use with other platforms- either directly in the browser, or in a system.
And very Important:
Ideally, it is considered a good practice to clean the /dist folder before each build.
This definitely helped me. Hope this helps you too.
Something went wrong in the package installation
you can do for re-install:
rm -rf node_modules
then
npm install
This is my package.json file:
{
"name": "pro-mern-stack",
"version": "1.0.0",
"description": "first init",
"main": "index.js",
"scripts": {
"start": "nodemon server.js server.js",
"compile": "babel src --presets react,es2015 --out-dir static",
"watch": "babel src --presets react,es2015 --out-dir static --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Yusuf",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongodb": "latest"
},
"devDependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.2"
}
}
I'M TRYING TO RUN npm start TO START THE WATCHER BUT I KEEP GETTING THIS ERROR:
> nodemon server.js server.js
C:\MERN\pro-mern-stack\node_modules\nodemon\lib\monitor\run.js:356
let sig = signal.replace('SIG', '');
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
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)
at Object.<anonymous> (C:\MERN\pro-mern-stack\node_modules\nodemon\lib\monitor\index.js:2:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! code ELIFECYCLE
npm ERR! pro-mern-stack#1.0.0 start: `nodemon server.js server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pro-mern-stack#1.0.0 start script 'nodemon server.js server.js'.
npm ERR! This is most likely a problem with the pro-mern-stack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nodemon server.js server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs pro-mern-stack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls pro-mern-stack
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\mern\pro-mern-stack\npm-debug.log
I'm running with powershell on windows 10. I've tried installing globally, didn't work. Also have the latest version of nodemon. Please, how can i fix this? I've reinstalled nodemon several times, keep getting the same error, even when I run it directly in the console. Thanks!
I see issue in the npm script. You should just update it to nodemon server.js
I have started with electron today and followed a guide to create a simple application browser window and I ran npm start in the command window and it displayed a lot of errors after I had entered it, I have posted the information below and my code.
Console error:
C:\Users\Administrator\Desktop\electron>npm start
> breef#1.0.0 start C:\Users\Administrator\Desktop\electron
> node index.js
module.js:471
throw err;
^
Error: Cannot find module 'app'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Administrator\Desktop\electron\index.js:1:73)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.9.2
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! breef#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the breef#1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the breef package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs breef
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls breef
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Administrator\Desktop\electron\npm-debug.log
Here is my package.json:
{
"name": "breef",
"version": "1.0.0",
"description": "A simple chat application.",
"main": "index.js",
"dependencies": {
"electron": "^1.4.12"
},
"devDependencies": {},
"scripts": {
"test": "breeftestcmd",
"start": "node index.js"
},
"keywords": [
"breef"
],
"author": "Sage & Sh4wn",
"license": "ISC"
}
Here is my index.js:
var app = require("app")
var browserWindow = require("browser-window")
app.on('ready', function() {
var mainWindow = new browserWindow({
width: 800,
height: 600
})
mainWindow.loadUrl('http://google.com');
})
If app is a module, it's missing in your package.json. If not, you should use a path to require it
var app = require('./app');
The guide you followed is out of date, as of Electron v1.0.0 the way built-in Electron modules are imported has changed. This is the correct way:
const {app, BrowserWindow} = require("electron")
You may also find it beneficial to read the previous question that covered this topic: What's the proper way to require in Node.js?
I stumbled upon this error when trying to start my application via NPM start. I am not sure where the problem lies, because it worked fine in my other computer (I unzip the file to this computer ran, npm install just in case and then tried to start it, but then the following error is thrown below).
Any help would be appreciated.
module.js:340
throw err;
^
Error: Cannot find module './'
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> (/mnt/c/Users/Jonathan/Desktop/client/<NAME>/node_modules/.bin/electron:3:16)
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)
npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v0.10.46
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! <NAME>#0.0.0 start: `electron main.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the <NAME>#0.0.0 start script 'electron main.js'.
npm ERR! This is most likely a problem with the <NAME> package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! electron main.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs <NAME>
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls <NAME>
npm ERR! There is likely additional logging output above.
package.json
{
"name": "<NAME>",
"version": "0.0.0",
"description": "[..]",
"main": "index.js",
"build": {
"appId": "test.321",
"app-category-type": "your.app.category.type",
"win": {
"iconUrl": "http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png"
}
},
"scripts": {
"start": "electron main.js",
"postinstall": "install-app-deps",
"pack": "build --dir",
"dist": "build"
},
"author": "john#gmail.com>",
"license": "ISC",
"devDependencies": {
"electron": "^1.3.3",
"electron-installer-squirrel-windows": "^1.3.0",
"electron-packager": "^7.5.1"
}
}
UPDATE
After solving the above error, the following error is thrown
I am running this through bash on windows 10, and have tried to install all required libraries to get the electron app to start via npm start on windows (works fine in my ubuntu)
electron main.js
[8002:0814/084446:FATAL:render_sandbox_host_linux.cc(40)] Check failed: 0 == shutdown(renderer_socket_, SHUT_RD). shutdown: Invalid argument
#0 0x000001e098ce <unknown>
#1 0x000001e1f4db <unknown>
#2 0x000001e1fa9d <unknown>
#3 0x000002892fc2 <unknown>
#4 0x00000265e599 <unknown>
#5 0x000002664b5f <unknown>
#6 0x00000265dc36 <unknown>
#7 0x000001204157 <unknown>
#8 0x000001202c30 <unknown>
#9 0x0000033a9470 main
#10 0x7fe5ec701f45 __libc_start_main
#11 0x000000575039 <unknown>
The shutdown check fail is a known issue. Electron runs just fine as a native Windows app, so just do that instead of over-complicating things with Bash on Windows.