I'm creating a website with Nuxt 3 and Express 4 and trying to deploy it via git on a Gandi Simple Hosting instance. While it works well locally (Node.js 16.13.0), when deployed (Node.js 17.4) I have this error caused by the unenv package import:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './runtime/polyfill/fetch.node' is not defined by "exports" in /srv/data/web/vhosts/default/client/.output/server/node_modules/unenv/package.json imported from /srv/data/web/vhosts/default/client/.output/server/index.mjs
at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
at packageExportsResolve (internal/modules/esm/resolve.js:496:3)
at packageResolve (internal/modules/esm/resolve.js:618:14)
at moduleResolve (internal/modules/esm/resolve.js:670:18)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:784:11)
at Loader.resolve (internal/modules/esm/loader.js:85:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:51:40)
at link (internal/modules/esm/module_job.js:50:36) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
I'm not the only one who have this error, as it can be seen in this open issue, concerning deployment on Firebase: https://github.com/nuxt/framework/issues/2151.
The unnev package.json distributed with the Nuxt 3 nitro server is:
{
"name": "unenv",
"version": "0.4.3",
"description": "",
"repository": "unjs/unenv",
"license": "MIT",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
"./runtime/*": {
"require": "./runtime/*.cjs",
"import": "./runtime/*.mjs"
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"runtime"
],
"scripts": {
"build": "unbuild",
"lint": "eslint --ext ts .",
"prepack": "unbuild",
"release": "standard-version && npm publish && git push --follow-tags"
},
"dependencies": {
"buffer": "^6.0.2",
"defu": "^5.0.0",
"events": "^3.2.0",
"inherits": "^2.0.4",
"mime": "^2.4.6",
"node-fetch": "^3.0.0",
"process": "^0.11.10",
"upath": "^2.0.1",
"util": "^0.12.4"
},
"devDependencies": {
"#nuxtjs/eslint-config-typescript": "latest",
"#types/node": "latest",
"#types/node-fetch": "latest",
"consola": "latest",
"eslint": "latest",
"standard-version": "latest",
"typescript": "latest",
"unbuild": "latest"
}
}
This non-Nuxt issue (Storybook.js) suggests that before Node 17 only a warning was thrown.
Even if I can consider downgrading my Node.js version, I would like to know if this error can be fixed on Node.js 17 and, if not, how the "exports" entry could be refactored to make it work.
Related
It looks like import modules errors.
This is my package.json settings, can anyone point me what am I missing ?
Thanks.
{
"name": "prj",
"version": "1.0.0",
"scripts": {
"dev": "vite --port 8080",
"build": "vite build",
"serve": "vite preview --port 8000",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest"
},
"jest": {
"moduleFileExtensions": ["js", "json", "vue"],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
}
},
"dependencies": {
"axios": "^0.21.1",
"vue": "^3.2.6",
"vue-i18n": "^9.1.7",
"vue-router": "^4.0.11",
"vuex": "^4.0.2"
},
"devDependencies": {
"#babel/core": "^7.15.5",
"#vitejs/plugin-vue": "^1.6.0",
"#vue/compiler-sfc": "^3.0.5",
"#vue/test-utils": "^2.0.0-rc.14",
"babel-jest": "^26.6.3",
"vite": "^2.5.1",
"vue-jest": "^5.0.0-alpha.10"
}
}
ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
FAIL src/tests/examples.test.js
● Test suite failed to run
Jest encountered an unexpected token
......
Details:
/some/path/src/tests/examples.test.js:4
import HomePage from './src/views/HomePage.vue';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
I am using webpack and had the same error that I fixed installing babel-core bridge:
npm install --save-dev babel-core#^7.0.0-bridge.0
I needed also the following one in jest.config.js:
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1',
},
Documentation
I created a Electron.js project like that :
install node 14
install vue-cli
create template project vue with : vue create myproject
install electron wrapper like this : vue add electron builder
install better-sqlite3 library
And when I run this command : npm run electron:serve
I have an error into inspect of browser electron like this :
Uncaught TypeError: Cannot read property 'modules' of undefined
at Object.eval (bindings.js?dfc1:29)
at eval (bindings.js:223)
at Object../node_modules/bindings/bindings.js (chunk-vendors.js:142)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (database.js?4c26:9)
at Object../node_modules/better-sqlite3/lib/database.js (chunk-vendors.js:59)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (index.js?f4f1:2)
and if I enter into bindings.js code I can find where is the error :
nodePreGyp:
'node-v' +
process.versions.modules** +
The loader of this file don't know process env variable of nodejs.
Why node js doesn't knowing it's process variable, it's strange ?
If Electron to do well to start browser, the issue is around the renderer process ?
But it seems to be better-sqlite3 module is concerned because error start with loading this library with webpack ?
there is my package.json file :
{
"name": "electron-project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"#types/better-sqlite3": "^5.4.1",
"better-sqlite3": "^7.1.1",
"core-js": "^3.6.5",
"node-sass": "4.14.1",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"#types/chai": "^4.2.11",
"#types/electron-devtools-installer": "^2.2.0",
"#types/mocha": "^5.2.4",
"#typescript-eslint/eslint-plugin": "^2.33.0",
"#typescript-eslint/parser": "^2.33.0",
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-e2e-cypress": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-plugin-typescript": "~4.5.0",
"#vue/cli-plugin-unit-mocha": "~4.5.0",
"#vue/cli-plugin-vuex": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/eslint-config-typescript": "^5.0.2",
"#vue/test-utils": "^1.0.3",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"electron": "^9.0.0",
"electron-devtools-installer": "^3.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass-loader": "^8.0.2",
"spectron": "11.0.0",
"typescript": "~3.9.3",
"vue-cli-plugin-electron-builder": "~2.0.0-rc.5",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"#vue/typescript/recommended"
],
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {},
"overrides": [
{
"files": [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)"
],
"env": {
"mocha": true
}
}
]
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
If I comment code line with import better-sqlite3 I don't have the issue.
Can you tell me where is the problem or help me to more understand how fix this...
Thank you
This issue has an origin from webpack auto managed by vue cli.
If you want to use better-sqlite3 library (or for similar issue) with vue and loading your project with webpack WRAPPED by vue into vue-cli, you need to add this into the vue.config.js
configureWebpack: {
externals: {
'better-sqlite3': 'commonjs better-sqlite3'
},
},
WARNING : you can use vue-cli and webpack without this specific file into your project because vue-cli managed that for you. But if you want to more customize vue-cli you need to add manually this file (which merged with the base vue.config.js that hidden by vue-cli).
I'm working on Windows environment and trying to run a forked node.js + typescript project.
This is my package.json :
{
"name": "my-task",
"version": "1.0.0",
"private": true,
"main": "dist/main.js",
"scripts": {
"start": "tsc-watch --onSuccess 'node -r source-map-support/register .'",
"test": "jest",
"lint": "eslint --cache '{src,test}/**/*.ts'"
},
"dependencies": {
"#types/express": "^4.17.7",
"#types/node": "^12.12.53",
"express": "^4.17.1",
"get-port": "^5.1.1",
"got": "^11.5.1",
"source-map-support": "^0.5.19"
},
"devDependencies": {
"#types/jest": "^26.0.8",
"#typescript-eslint/eslint-plugin": "^3.8.0",
"#typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.20.0",
"jest": "^26.2.2",
"prettier": "^2.0.5",
"ts-jest": "^26.1.4",
"tsc-watch": "^4.2.9",
"typescript": "^4.0.2"
}
}
For some reason, i'm getting the following error:
error TS5023: Unknown compiler option '-r'.
I tried to remove the -r, but then i'm getting these errors:
error TS6054: File '.'' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6231: Could not resolve the path 'source-map-support/register' with the extensions: '.ts', '.tsx', '.d.ts'.
and server won't start.
I ran npm uninstall + npm install - nothing seems to solve these issues.
Can anyone assist?
EDITED:
ts.config:
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"]
}
Good day:
I've just installed Babel Preset-ENV through NPM and getting this issue:
[nodemon] starting `babel-node server.js server.js`
/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
throw e;
^
TypeError: Cannot read property 'loose' of undefined (While processing preset: "/home/vagrant/api/node_modules/#babel/preset-env/lib/index.js")
at _default (/home/vagrant/api/node_modules/#babel/plugin-transform-modules-commonjs/lib/index.js:19:22)
at Function.memoisePluginContainer (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (native)
at Function.normalisePlugins (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (native)
My Package.JSON is the following:
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon -L server.js --ignore 'db/schema.json' --exec babel-node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"#babel/core": "^7.0.0-beta.32",
"#babel/preset-env": "^7.0.0-beta.32",
"babel-core": "^6.26.0",
"express": "^4.16.2",
"express-graphql": "^0.6.11",
"express-oauth-server": "^2.0.0",
"graphql": "^0.11.7",
"jsonwebtoken": "^8.1.0",
"mongo": "^0.1.0",
"mongoose": "^4.13.2",
"password-hash": "^1.2.2",
"react-relay": "^1.4.1"
},
"devDependencies": {
"babel-cli": "^6.26.0"
}
}
And also my .babelrc is this:
vagrant#vagrant-ubuntu-trusty-64:~/api$ cat .babelrc
{
"presets": [
["#babel/preset-env", {
"targets": {
"node": "current"
}
}]
]
}
Before the upgrade I was using stage-0 and es2015 presets that were working however, after the upgrade this has been buggy. Note, my NPM version is 4.6.1.
Thanks.
Make sure your Babel dependencies are compatible with each other.
this:
"#babel/core": "^7.0.0-beta.32",
"#babel/preset-env": "^7.0.0-beta.32",
"babel-core": "^6.26.0",
"babel-cli": "^6.26.0"
should be this:
"#babel/cli": "^7.0.0-beta.34",
"#babel/core": "^7.0.0-beta.34",
"#babel/node": "^7.0.0-beta.34",
I followed this instruction for setup https://github.com/babel/babel/tree/master/experimental/babel-preset-env however, the documentation here seems outdated. I was advised to use the official babel documentation mentioned here for the preset setup https://babeljs.io/
package.json:
{
"name": "flux-pricing",
"version": "0.0.1",
"description": "Pricing component with flux",
"main": "js/app.js",
"dependencies": {
"flux": "^2.0.0",
"jest-cli": "^0.5.0",
"jsdom": ">= 0.1.23 < 4.0.0",
"react": "^0.12.0",
"underscore": "^1.7.0"
},
"devDependencies": {
"browserify": "~6.2.0",
"envify": "~3.0.0",
"react": "^0.12.0",
"reactify": "^0.15",
"watchify": "~2.1.0",
"gulp": "~3.8.9",
"gulp-browserify": "~0.5.0",
"gulp-concat": "~2.4.1",
"node-jsx": "~0.2.0",
"express": "~4.0.0"
},
"scripts": {
"start": "watchify -o js/bundle.js -v -d .",
"build": "browserify . | uglifyjs -cm > js/bundle.min.js",
"test": "jest"
},
"jest": {
"rootDir": "./js"
},
"browserify": {
"transform": [
"reactify",
"envify"
]
}
}
after npm install when i try to do npm test
s\jsdom\lib\jsdom.js:3
`jsdom 4.x onward only works on io.js, not Node.jsT: https://github.com/tmpvar
^
Unexpected token ILLEGAL
how to resolve this issue?
I had the same problem. The solution is to switch to use Jest 0.4 instead.
Here's the issue from github.
https://github.com/facebook/jest/issues/469#issuecomment-133105627
I actually had to downgrade to Jest 0.3 and node 10.x to get the Jest React example working. Here's the reference
https://github.com/facebook/jest/issues/427