Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR. _import_meta_url_ is not defined #743

Open
lagarciam opened this issue Apr 14, 2023 · 2 comments
Open

ERROR. _import_meta_url_ is not defined #743

lagarciam opened this issue Apr 14, 2023 · 2 comments

Comments

@lagarciam
Copy link

Environment


  • Operating System: Linux
  • Node Version: v16.14.0
  • Nuxt Version: 0.0.0
  • Nitro Version: -
  • Package Manager: npm@8.3.1
  • Builder: webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Is a private project, but I can show the dependencies in the package.json:

"dependencies": {
"@ax2/gpt-ads-module": "^0.6.0",
"@nuxtjs/axios": "^5.13.6",
"@staszek998/v-html": "^1.0.6",
"@vuejs-community/vue-filter-date-parse": "^1.1.6",
"dotenv": "^16.0.1",
"fs": "^0.0.1-security",
"jsdom": "^20.0.0",
"node-dependency-injection": "^2.7.1",
"nuxi": "^0.10.1",
"nuxt": "^2.16.3",
"simple-vdom": "^0.0.3",
"slug": "^5.3.0",
"std-env": "^3.0.1",
"universal-dom-parser": "^0.0.3",
"validator": "^13.7.0",
"virtual-dom-library": "^1.0.0",
"vue": "^2.7.14",
"vue-demi": "^0.12.5",
"vue-lazy-hydration": "^2.0.0-beta.4",
"vue-plugin-load-script": "^1.3.5",
"xss-filters": "^1.2.7"
},
"devDependencies": {
"@babel/eslint-parser": "^7.14.7",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@nuxt/bridge": "npm:@nuxt/bridge-edge@latest",
"@nuxt/types": "^2.15.7",
"@nuxtjs/device": "^2.1.0",
"@nuxtjs/eslint-config-typescript": "^6.0.1",
"@nuxtjs/eslint-module": "^3.0.2",
"@nuxtjs/router": "^1.6.1",
"@nuxtjs/style-resources": "^1.2.1",
"@testing-library/dom": "^7.31.2",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/user-event": "^14.4.3",
"@testing-library/vue": "^5.8.3",
"@types/jest": "^27.5.2",
"@types/slug": "^5.0.3",
"@vue/test-utils": "^1.3.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^27.0.5",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-nuxt": "^2.0.0",
"eslint-plugin-vue": "^7.12.1",
"husky": "^6.0.0",
"ignore-loader": "^0.1.2",
"jest": "^27.5.1",
"json-server": "^0.17.0",
"lint-staged": "^10.5.4",
"prettier": "^2.3.2",
"sass": "^1.44.0",
"sass-loader": "^10.2.0",
"standard-version": "^9.3.2",
"ts-jest": "^27.1.5",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript-eslint-parser": "^22.0.0",
"vue-jest": "^3.0.7"
},

Describe the bug

When I run in a "dev" mode "nuxi dev", with nuxt bridge "@nuxt/bridge": "npm:@nuxt/bridge-edge@latest", and "nuxt": "^2.16.3", dependencies it breaks with the next error:

✔ Nitro built in 945 ms nitro 13:20:27
ℹ Waiting for file changes 13:20:27

ERROR [worker reload] [worker init] import_meta_url is not defined 13:20:28

at .nuxt/dev/index.mjs:1:30
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24) 13:20:03
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)

It doesn't work and I can't run in dev mode.

But when I build the project with "nuxi build" and start the node server it works.

I seems that nitro breaks in the next file:
\node_modules\nitropack\dist\shared\nitro.XXXXX.mjs:

function importMeta(nitro) {
const ImportMetaRe = /import.meta|globalThis.importMeta/;
return {
name: "import-meta",
renderChunk(code, chunk) {
const isEntry = chunk.isEntry;
if (!isEntry && (!ImportMetaRe.test(code) || code.includes("ROLLUP_NO_REPLACE"))) {
return;
}
const url = nitro.options.node && isEntry ? "import_meta_url" : '"file:///_entry.js"';
const env = nitro.options.node ? "process.env" : "{}";
const ref = "globalThis.importMeta";
const stub = {url:${url},env:${env}};
const stubInit = isEntry ? ${ref}=${stub}; : ${ref}=${ref}||${stub};;
return {
code: stubInit + code,
map: null
};
}
};
}

Additional context

No response

Logs

No response

Copy link
Member

This is something that Nitro should inject in your code. Would you run pnpm why nitropack (or equivalent for your package manager)?

@lagarciam
Copy link
Author

nitropack@2.3.3 dev
node_modules/nitropack
  nitropack@"^2.3.2" from @nuxt/bridge@3.0.0-27998567.a12a710
  node_modules/@nuxt/bridge
    dev @nuxt/bridge@"npm:@nuxt/bridge-edge@latest" from the root project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants