An error while trying to build bundle with webpack - javascript

I`ve just started to learn nodejs and react and I am trying to build bundle using webpack and I receive next error. How can I make it work?
C:\Users\Admin\WebstormProjects\reactandwebpacktests>webpack
C:\Users\Admin\WebstormProjects\reactandwebpacktests\node_modules\v8-compile-cache\v8-compile-cache.js:161
return mod.npm require(id);
^^^^^^^
SyntaxError: Unexpected identifier
?[90m at wrapSafe (internal/modules/cjs/loader.js:1054:16)?[39m
?[90m at Module._compile (internal/modules/cjs/loader.js:1102:27)?[39m
?[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)?[39m
?[90m at Module.load (internal/modules/cjs/loader.js:986:32)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:879:14)?[39m
?[90m at Module.require (internal/modules/cjs/loader.js:1026:19)?[39m

Related

Getting started with Mongoose

When I put in the code
const mongoose = require("mongoose")
I get back the following error:
/Users/user/shares3/node_modules/mongodb/lib/utils.js:1069
catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/user/shares3/node_modules/mongodb/lib/operations/add_user.js:6:17)
This code is as simple as could be. I have tried reinstalling the mongoose package.
Do you have any ideas on how I can troubleshoot this?
The issue is caused by using a (very) old version of Node.js that doesn't support try/catch.

Problem to execute gulp server at legacy app

Yo guys!
I get early a job on a legacy app, using gulpjs
After having installed all dependencies, when I try execute the application with "gulp server", get the following error at console:
D:\scripts\node_modules\gulp-sass\index.js:186
).toString();
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Playkids\playkids-simple-pages\scripts\tasks\development.js:4:12)

Unexpected token when running grunt build

I'm trying to execute the following command grunt build but when trying it the below error message appear
PS C:\Users\EDMA\Documents\Tutenlabs\Bitbucket\tuten-macarena-backoffice-web> grunt build
C:\Users\EDMA\AppData\Roaming\nvm\v6.16.0\node_modules\grunt-cli\node_modules\micromatch\index.js:44
let isMatch = picomatch(String(patterns[i]), { ...options, onResult }, true);
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\EDMA\AppData\Roaming\nvm\v6.16.0\node_modules\grunt-cli\node_modules\findup-sync\index.js:12:10)
I navigate to C:\Users\EDMA\AppData\Roaming\nvm\v6.16.0\node_modules\grunt-cli\node_modules\micromatch\index.js:44 path and looked for index.js file to check whether there's an error or not, but the strange thing is there isn't. Any idea what's going on here?
Aditionally, this is AngularJS.

Using function from module in JavaScript script

I want to use an exported constant from a JS module. My simple script is like
#!/usr/bin/env node
const pi = require('./custom_math').pi
console.log(pi)
But the module I require has an import, so It raises the following error:
$ ./script.js
<path_to_module>/index.js:1
import anotherconstant from '<other_module>'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (./script.js:3:12)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
How can I make a script that uses the pi constant from the simple_math/index.js file?

it gives "SyntaxError: Unexpected token" when importing express-handlebars

when I add this line error appears and if removed error disappears
const expressHandleBars = require('express-handlebars');
This is the error,
C:\Users\Hp\sample-project\node-mongodb-api\node_modules\express-handlebars\lib\express-handlebars.js:230
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
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)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Hp\sample-project\node-mongodb-api\node_modules\express-handlebars\index.js:9:25)
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)
at Module.require (module.js:497:17)
What version of Node.js are you using? Please check this issue.
The error cause by Trailing commas in function call feature. This feature had been implemented in Node v8 so you have to upgrade your Node.js to version 8+ to be able to use express-handlebars.

Categories

Resources