I'm creating a documentation project which I npm init'd. This is the relevant part of my package.json
"scripts": {
"lint": "remark --quiet --frail ."
},
"type": "module",
"dependencies": {
"remark-cli": "^10.0.0",
"remark-preset-lint-markdown-style-guide": "^5.0.0"
},
I would now like to lint the Markdown files with remark-cli:
`remark --quiet --frail .`
This is the error I'm getting:
<...>/node_modules/remark-cli/cli.js:2
import {createRequire} from 'node:module'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
I thought adding "type": "module" to package.json would solve this but no luck.
What am I doing wrong here?
Related
I want to install firebase in my JavaScript project. But when I open the .js script I have problem with import. How I can fix it?
Code:
import { initializeApp } from 'firebase/app';
Error:
(node:3168) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\Mr_Restmah\OneDrive - Technical University of Moldova\Desktop\Programare Calculatoare\Bulls and Cows\firebase.js:1
import { initializeApp } from 'firebase/app';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1084:15)
at Module._compile (node:internal/modules/cjs/loader:1119:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47
package.json
{
"type": "module",
"dependencies": {
"firebase": "^9.12.1",
"firebase-admin": "^11.2.0"
},
"devDependencies": {
"webpack-cli": "^4.10.0"
}
}
Try to set "type": "module" in the package.json
I am trying to call the cloudinary module to resize an image. This is my code:
import cloudinary from 'cloudinary';
var cl = new cloudinary.Cloudinary({ cloud_name: "username", secure: true });
new CloudinaryImage("pingu.jpg").resize(scale().width(70).height(53));
Here's the error I'm getting:
(node:29424) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
c:\Users\...\perspective\cloud.js:1
import cloudinary from 'cloudinary';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (node:internal/modules/cjs/loader:1018:16)
at Module._compile (node:internal/modules/cjs/loader:1066:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
at Module.load (node:internal/modules/cjs/loader:967:32)
at Function.Module._load (node:internal/modules/cjs/loader:807:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
[Done] exited with code=1 in 0.183 seconds
Can anyone tell me why I'm getting this specific error?
Use commonJs:
const cloudinary = require('cloudinary');
'Import' can only be used when the Node.JS file is ran as a module. Go to your package.json, and add in a key 'type' and the value 'module'.
{
"name": "test",
"version": "1.0.0",
"dependencies": {
...
}
}
to
{
"name": "test",
"version": "1.0.0",
"dependencies": {
...
},
"type": "module"
}
Alternatively, you could change your code from and then you don't need to edit your 'package.json' file
import something from Something
to
const something = require('Something')
I just started learning JavaScript by using Atom in order to create an online chart. Hence, I am quite unfamiliar with NPM, package.json and all that sort of things.
I want to import two modules by using the following code:
import * as am4core from "#amcharts/amcharts4/core";
import * as am4charts from "#amcharts/amcharts4/charts";
Which gives the following error message:
(node:17060) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\PF1VMKH9_ADM\Documents\herverkaveling\test:4
import * as am4core from "#amcharts/amcharts4/core";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.newLoader [as .js] (C:\Users\PF1VMKH9_ADM\.atom\packages\script\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at Object.<anonymous> (C:\Users\PF1VMKH9_ADM\.atom\packages\script\node_modules\#babel\node\lib\_babel-node.js:176:21)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
[Finished in 0.522s]
I added "type": "module" to the package.json file but it did not solve the issue:
{
"name": "packages",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type":"module",
"dependencies": {
"typescript": "^4.4.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
What am I doing wrong?
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"]]
}
I want to do some tests on canvas purely in node.js.
This is my package.json
{
"name": "test",
"description": "Test",
"version": "0.1.0",
"author": "anthony#work",
"dependencies": {
"canvas": "^1.6.7",
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"jsdom": "^11.3.0"
}
}
This is my .babelrc
{
"presets": ["env", "stage-0"]
}
This is my test javascript (a.js)
const { jsdom } = require('jsdom');
// main
jsdom();
console.log('done')
When I run the script, however,
npx babel a.js | nodejs -- -
I get this error:
/work/node_modules/jsdom/lib/api.js:10
const { URL } = require("whatwg-url");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at [stdin]:3:16
at Object.exports.runInThisContext (vm.js:54:17)
at Object.<anonymous> ([stdin]-wrapper:6:22)
What causes this error? How can I fix this error?
Version information:
Node.js: v4.2.6
OS: Ubuntu 16.04
You are running an incompatible node version with jsdom.
jsdom#10 requires nodejs v6. So either upgrade Node or downgrade jsdom.
Found info about that here: https://github.com/tmpvar/jsdom#jsdom