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

import.meta contains wrong data #1511

Closed
2 of 3 tasks
sionzee opened this issue Jan 13, 2021 · 2 comments
Closed
2 of 3 tasks

import.meta contains wrong data #1511

sionzee opened this issue Jan 13, 2021 · 2 comments

Comments

@sionzee
Copy link

sionzee commented Jan 13, 2021

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

Based on NodeJS doc or Mozzila doc the import.meta.url should return URL of the module.

Actually the import.meta is equal to this:

[Object: null prototype] {
  url: 'data:text/javascript,console.log(import.meta);\n' +
    'throw new Error();\n' +
    'var vite_config = {};\n' +
    '\n' +
    'export default vite_config;\n'
}

Reproduction

  1. Set your package's type to module.
  2. Create vite.config.ts and put there:
console.log(import.meta)
throw new Error() // otherwise the terminal will be emptied
export default {};
  1. Run vite or vite build

System Info

  • vite version: vite/2.0.0-beta.26 linux-x64 node-v14.13.0
  • Operating System: Windows 10 (WSL)
  • Node version: 14.13.0
  • Package manager (npm/yarn/pnpm) and version: yarn 1.22.5
@underfin
Copy link
Member

underfin commented Jan 13, 2021

You can remove your package's type to module as a workaround.

@yyx990803
Copy link
Member

Note for now we have to pre-transform import.meta.url because native ESM loader support is still experimental and we have to pre-bundle TS config files when using native ESM.

This maybe can be improved to use native loaders once it becomes stable in Node.

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

No branches or pull requests

3 participants