Mocha 6, Babel 7, ES6: SyntaxError: Unexpected token export - javascript

I'm trying to create a simple npm package based on another called 'sidebar-v2' (https://github.com/Turbo87/sidebar-v2)
For that reason, I've tried to update the JS code to ES6, however when I try to test if the updates are ok, the mocha raises an exception, that I send below:
> #rmmariano/ol-sb#1.0.0-rc.1 test /home/inpe/Documents/datainfo/npm_packages/ol-sb
> mocha --require #babel/register
/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/ol/control.js:5
export {default as Attribution} from './control/Attribution.js';
^^^^^^
SyntaxError: Unexpected token export
at new Script (vm.js:85:7)
at createScript (vm.js:266:10)
at Object.runInThisContext (vm.js:314:10)
at Module._compile (internal/modules/cjs/loader.js:698:28)
at Module._compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.newLoader [as .js] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/inpe/Documents/datainfo/npm_packages/ol-sb/src/ol3-sidebar.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Module._compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.newLoader [as .js] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/inpe/Documents/datainfo/npm_packages/ol-sb/src/index.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Module._compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.newLoader [as .js] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/inpe/Documents/datainfo/npm_packages/ol-sb/test/test.js:4:1)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Module._compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.newLoader [as .js] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:327:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:324:14)
at Mocha.run (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:801:10)
at Object.exports.singleRun (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run-helpers.js:207:16)
at exports.runMocha (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run.js:296:3)
at Object.runCommand (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/lib/command.js:238:44)
at Object.parseArgs [as _parseArgs] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:1089:24)
at Object.parse (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:566:25)
at Object.exports.main (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/cli.js:62:6)
at Object.<anonymous> (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/bin/_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
at internal/main/run_main_module.js:21:11
npm ERR! Test failed. See above for more details.
I've already tried to follow the answer of other questions on StackOverflow, such as:
Babel unexpected token import when running mocha tests
Unexpected token import, can not set up ES6 in my JS project with Mocha, Chai and Sinon
But no one of them worked to me, unfortunately.
When I try to update my .babelrc to:
{
"presets": ["#babel/preset-env", "es2015"]
}
The error changes to:
> #rmmariano/ol-sb#1.0.0-rc.1 test /home/inpe/Documents/datainfo/npm_packages/ol-sb
> mocha --require #babel/register
/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:1148
else throw err
^
Error: Cannot find module 'babel-preset-es2015' from '/home/inpe/Documents/datainfo/npm_packages/ol-sb'
at Function.module.exports [as sync] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/resolve/lib/sync.js:58:15)
at resolveStandardizedName (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/files/plugins.js:101:31)
at resolvePreset (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/files/plugins.js:58:10)
at loadPreset (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/files/plugins.js:77:20)
at createDescriptor (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:154:9)
at items.map (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:101:10)
at presets (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-chain.js:320:26)
at /home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/partial.js:85:55)
at loadFullConfig (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/full.js:43:39)
at loadOptions (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/index.js:27:36)
at OptionManager.init (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/index.js:231:36)
at compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/register/lib/node.js:61:42)
at compileHook (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/register/lib/node.js:102:12)
at Module._compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:93:29)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.newLoader [as .js] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:327:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:324:14)
at Mocha.run (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:801:10)
at Object.exports.singleRun (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run-helpers.js:207:16)
at exports.runMocha (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run.js:296:3)
at Object.runCommand (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/lib/command.js:238:44)
at Object.parseArgs [as _parseArgs] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:1089:24)
at Object.parse (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:566:25)
at Object.exports.main (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/cli.js:62:6)
at Object.<anonymous> (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/bin/_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
at internal/main/run_main_module.js:21:11
npm ERR! Test failed. See above for more details.
package.json
{
...
"scripts": {
"start": "nodemon --exec babel-node ./src/index.js",
"test": "./node_modules/.bin/mocha --require #babel/register"
},
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.3.4",
"#babel/node": "^7.2.2",
"#babel/preset-env": "^7.3.4",
"#babel/register": "^7.0.0",
"chai": "^4.2.0",
"mocha": "^6.0.2",
"nodemon": "^1.18.10"
},
"dependencies": {
"ol": "^5.3.1"
}
}
.babelrc
{
"presets": ["#babel/preset-env"]
}
Could someone help me?
Source code can be found here: https://github.com/rmmariano/ol-sb
Edit 1:
I've tried to update my .babelrc to:
{
"presets": ["#babel/preset-env", "es2015"]
}
And to install the package:
npm install -S babel-preset-es2015
But the following error starts to appear when I run "npm test":
> #rmmariano/ol-sb#1.0.0-rc.1 test /home/inpe/Documents/datainfo/npm_packages/ol-sb
> mocha --require #babel/register
/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:1148
else throw err
^
Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/babel-preset-es2015/lib/index.js
at createDescriptor (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:178:11)
at items.map (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:101:10)
at presets (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-chain.js:320:26)
at /home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/partial.js:85:55)
at loadFullConfig (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/full.js:43:39)
at loadOptions (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/config/index.js:27:36)
at OptionManager.init (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/core/lib/index.js:231:36)
at compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/register/lib/node.js:61:42)
at compileHook (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/#babel/register/lib/node.js:102:12)
at Module._compile (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:93:29)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.newLoader [as .js] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:327:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:324:14)
at Mocha.run (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/mocha.js:801:10)
at Object.exports.singleRun (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run-helpers.js:207:16)
at exports.runMocha (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/run.js:296:3)
at Object.runCommand (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/lib/command.js:238:44)
at Object.parseArgs [as _parseArgs] (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:1089:24)
at Object.parse (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:566:25)
at Object.exports.main (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/lib/cli/cli.js:62:6)
at Object.<anonymous> (/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/mocha/bin/_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
at internal/main/run_main_module.js:21:11
npm ERR! Test failed. See above for more details.
Edit 2:
I've tried to update my .babelrc to:
{
"presets": ["#babel/preset-env", "#babel/preset-es2015"]
}
And to install the package:
npm install -S #babel/preset-es2015
But the following error starts to appear when I run "npm test":
> #rmmariano/ol-sb#1.0.0-rc.1 test /home/inpe/Documents/datainfo/npm_packages/ol-sb
> mocha --require #babel/register
/home/inpe/Documents/datainfo/npm_packages/ol-sb/node_modules/yargs/yargs.js:1148
else throw err
^
Error: Cannot find module '#babel/preset-es2015' from '/home/inpe/Documents/datainfo/npm_packages/ol-sb'

Short solution. I had a similar problem with imports and exports.
Also, Babel did not work well with mocha version 7.2.0 and npm version 6.14.4. So I solved the problem using esm version 3.2.25.
npm install --save-dev esm
My package.json is using this:
"scripts": {
"test": "mocha -r esm --exit"
}

I was searching through the whole internet to find a solution. I came up with this:
npx mocha --require ts-node/register --require esm src/**/*.spec.ts
Or in package.json scripts (both options work, choose whichever you like):
"scripts": {
"test": "mocha -r esm -r ts-node/register src/**/*.spec.ts",
"test-ts": "ts-mocha -r esm -p tsconfig.json src/**/*.spec.ts"
}
And don't forget to add esm to devDependencies:
npm install --save-dev esm
so in package.json it is gonna be
"devDependencies": {
"esm": "^3.2.25"
}

I get your code on github, and I see your problem.
This problem is in your ol3-sidebar.js, in this file on first line you import a function from file ol/control.js, but this file is not present in your workspace. So it is giving error when running the tests.

I had the same problem. And managed to solve it after re-installing windows and it still not working.
For me it was that the project folder was on a different drive accessed via a symbolic link. I have a small SSD for boot so keep project folders on a second larger disk drive, and symlink from my home directory to this folder.
If i navigate directly to the folder it works.
I'll report this to both Mocha and Babel teams. I'm not sure who's problem this is.

I think your problem(s) come from Babel. Try first:
npx babel-upgrade
to see the modifications that the package babel-upgrade will do without applying them, and if your are satisfied:
npx babel-upgrade --write
to apply the modifications.

I had a similar problem and had to run
npm install --save-dev core-js#3
My .bablerc was:
{
"presets": [["#babel/preset-env"]]
}

Related

Why npm run dev command is showing error cannot find module '. /dist/rx'

C:\Users\sharm\codeweb\eth-to-do-list>npm run dev
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> eth-to-do-list#1.0.0 dev
> lite-server
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './dist/rx'
Require stack:
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\rx\index.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\browser-sync\dist\file-watcher.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\browser-sync\dist\browser-sync.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\browser-sync\dist\index.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\lite-server\lib\lite-server.js
- C:\Users\sharm\codeweb\eth-to-do-list\node_modules\lite-server\bin\lite-server
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\sharm\codeweb\eth-to-do-list\node_modules\rx\index.js:1:10)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159: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) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\rx\\index.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\browser-sync\\dist\\file-watcher.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\browser-sync\\dist\\browser-sync.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\browser-sync\\dist\\index.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\lite-server\\lib\\lite-server.js',
'C:\\Users\\sharm\\codeweb\\eth-to-do-list\\node_modules\\lite-server\\bin\\lite-server'
]
}

TypeError: Cannot read properties of undefined (reading 'create'). Happens when running npm run build:ssr

Getting an error when running npm run build:ssr to try to deploy my angular application
The error:
firestarter#0.0.0 compile:server
webpack --config webpack.server.config.js --progress --colors
C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:93
throw err;
^
TypeError: Cannot read properties of undefined (reading 'create')
at Object. (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\webpack.server.config.js:5:39)
at Module._compile (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157: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 (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at WEBPACK_OPTIONS (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:114:13)
at requireConfig (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:116:6)
at C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:123:17
at Array.forEach ()
at module.exports (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\utils\convert-argv.js:121:15)
at C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:71:45
at Object.parse (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\node_modules\yargs\yargs.js:576:18)
at C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:49:8
at Object. (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack-cli\bin\cli.js:366:3)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157: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 runCli (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack\bin\webpack.js:54:2)
at Object. (C:\Users\2998542\Documents\DeveloperPortfolio\Projects\firestarter\node_modules\webpack\bin\webpack.js:147:2)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
See the code below that the error is pointing to.
I've been trying to figure out why is giving me that error for weeks now.
const webpack = require('webpack');
const WebpackConfigFactory = require('#nestjs/ng-universal')
.WebpackConfigFactory;
module.exports = WebpackConfigFactory.create(webpack, {
// Nest server for SSR
server: './server/main.ts'
});
WebpackConfigFactory no longer exists as Angular is now using CLI Builders to build & serve SSR apps.
Issue reported here

Can't run require('opencv4nodejs')

I'm using macOS Monterey 12.2.1, Apple M1. And in the project directory, I installed opencv-build and opencv4nodejs by this script code:
"scripts": { "postinstall": "npm i opencv-build && npm i opencv4nodejs" }
When I run cv = require('opencv4nodejs'), I got this error message and I can't understand it. How can I run this code correctly?
/usr/local/bin/node /Users/david/Desktop/project2/main.js
/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js:47
throw err
^
Error: Cannot find module '/Users/david/Desktop/project2/node_modules/opencv4nodejs/build/Release/opencv4nodejs'
Require stack:
- /Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js
- /Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/opencv4nodejs.js
- /Users/david/Desktop/project2/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js:40:8)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155: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) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/cv.js',
'/Users/david/Desktop/project2/node_modules/opencv4nodejs/lib/opencv4nodejs.js',
'/Users/david/Desktop/project2/main.js'
]
}
Process finished with exit code 1
Use Node 14.18.1, then uninstall opencv4nodejs.
Run export CXXFLAGS="-std=c++14 -Wno-c++11-narrowing"
Run npm install opencv4nodejs

SyntaxError: Unexpected identifier with mocha and babel

I have a mocha test file (test/test.js) that starts like this, using ES6 module syntax:
import {promises as fs} from 'fs'
import stepToD3 from '../src/StepToD3'
import assert from "assert"
In addition, I have a babel.config.js file in the root of my project:
module.exports = {
presets: [
"#vue/app",
"#babel/preset-env"
]
}
I then want to test this using Mocha, transpiled through babel. I do so using mocha --require #babel/register test/test.js. However, somewhere during the execution, this fails with the following error:
/home/michael/Programming/cola-step/node_modules/#babel/runtime-corejs2/helpers/esm/asyncToGenerator.js:1
(function (exports, require, module, __filename, __dirname) { import _Promise from "../../core-js/promise";
^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Module._compile (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Object.newLoader [as .js] (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/michael/Programming/cola-step/test/test.js:7:49)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Module._compile (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Object.newLoader [as .js] (/home/michael/Programming/cola-step/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at /usr/lib/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/usr/lib/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run (/usr/lib/node_modules/mocha/lib/mocha.js:536:10)
at Object.<anonymous> (/usr/lib/node_modules/mocha/bin/_mocha:573:18)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Why is this failing to understand the ES6 import syntax if I'm using Babel? What is going wrong here?
In this case, I was running my tests with mocha on NodeJS, but my babel.config.js was set up to produce code for the browser. To fix this, I had to create two different babel settings, and then export the right NODE_ENV value before running the appropriate command (e.g. NODE_ENV=test mocha --require #babel/register for tests, and NODE_ENV=production for my webpack production build).
This is my new babel.config.js:
module.exports = {
'env': {
'production': {
'presets': [
[
'#vue/app',
{
// "modules": false,
'targets': ['ie >= 9']
},
'#babel/env'
]
],
'comments': false
},
'test': {
'presets': [
[
'#babel/env',
{'targets': {'node': 'current'}}
]
]
}
}
}

i have an error at nodejs with 'oracledb'

I have an error with oracledb modules.
I have successed to install oracledb.
when i typed like this,
-> npm install oracledb
njsOracle.cpp
njsPool.cpp
njsConnection.cpp
njsResultSet.cpp
njsMessages.cpp
njsIntLob.cpp
dpiEnv.cpp
dpiEnvImpl.cpp
dpiException.cpp
dpiExceptionImpl.cpp
dpiConnImpl.cpp
dpiDateTimeArrayImpl.cpp
dpiPoolImpl.cpp
dpiStmtImpl.cpp
dpiUtils.cpp
dpiLob.cpp
dpiCommon.cpp
win_delay_load_hook.cc
C:\Users\aaa\AppData\Roaming\npm\node_modules\oracledb\build\Release\oracledb.lib 라이브러리 및 C:\Users\aaa
\AppData\Roaming\npm\node_modules\oracledb\build\Release\oracledb.exp 개체를 생성하고 있습니다.
코드를 생성하고 있습니다.
코드를 생성했습니다.
oracledb.vcxproj -> C:\Users\aaa\AppData\Roaming\npm\node_modules\oracledb\build\Release\oracledb.node
oracledb.vcxproj -> C:\Users\aaa\AppData\Roaming\npm\node_modules\oracledb\build\Release\oracledb.pdb (Full PDB)
C:\Users\GwiTtaeGi\AppData\Roaming\npm
`-- oracledb#1.13.1
but when i execute require('oracledb'), there's an error like this.
Error: The specified procedure could not be found.
\?\c:\testnode\test\node_modules\oracledb\build\Release\oracledb.node
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
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. (c:\testnode\test\node_modules\oracledb\lib\oracledb.js:35:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
I can't fix this error..
version is..
node -v : v6.10.3
npm -v : 4.5.0
Firstly, try to clean NPM cache
rm -rf ~/.node-gyp ~/.npm; npm cache clean
If error still occurs, try set NODE_PATH environment variable

Categories