I'm currently learning how to create API with typescript using module-alias. When it comes to import some of them works fine, but some causes errors depite of fact that they are written in the same way.
Example: (this works fine)
import PostModel from './post.model';
import Post from '#/resources/post/post.interface';
Example (this causes error)
import PostModel from '#/resources/post/post.model';
import Post from '#/resources/post/post.interface';
Error:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '#/resources/post/post.model'
Require stack:
- C:\code\js\actual\expess-type\dist\resources\post\post.service.js
- C:\code\js\actual\expess-type\dist\resources\post\post.controller.js
- C:\code\js\actual\expess-type\dist\index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._resolveFilename (C:\code\js\actual\expess-type\node_modules\module-alias\index.js:49:29)
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:\code\js\actual\expess-type\dist\resources\post\post.service.js:15:38)
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) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\code\\js\\actual\\expess-type\\dist\\resources\\post\\post.service.js',
'C:\\code\\js\\actual\\expess-type\\dist\\resources\\post\\post.controller.js',
'C:\\code\\js\\actual\\expess-type\\dist\\index.js'
]
}
My file structure
package.json
"_moduleAliases": {
"#/resources:": "dist/resources",
"#/utils": "dist/utils",
"#/middleware": "dist/middleware"
}
tsconfig.json
"paths": {
"#/resources/*": ["resources/*"],
"#/utils/*": ["utils/*"],
"#/middleware/*": ["middleware/*"]
}
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'
]
}
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
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
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"]]
}