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

[Bug Report]: cannot use 'import.meta' outside a module #2392

Closed
9aoy opened this issue Mar 21, 2023 · 2 comments · Fixed by #2684
Closed

[Bug Report]: cannot use 'import.meta' outside a module #2392

9aoy opened this issue Mar 21, 2023 · 2 comments · Fixed by #2684
Assignees
Labels
team The issue/pr is created by the member of Rspack.

Comments

@9aoy
Copy link
Collaborator

9aoy commented Mar 21, 2023

System Info

System:

  • OS: macOS 12.5.1
  • CPU: (10) arm64 Apple M1 Pro
  • Memory: 212.05 MB / 32.00 GB
  • Shell: 5.8.1 - /bin/zsh

Binaries:

  • Node: 16.19.1 - /usr/local/bin/node
  • Yarn: 1.22.19 - /usr/local/bin/yarn
  • npm: 8.19.3 - /usr/local/bin/npm

Browsers:

  • Chrome: 111.0.5563.64
  • Safari: 15.6.1

npmPackages:

  • @rspack/cli: latest => 0.1.1

Details

runtime error when use some esm libs which have some import.meta syntax, like zustand

image

image

image

Reproduce link

https://github.com/9aoy/rspack-issue-reproduce/tree/main/import-esm

Reproduce Steps

  1. pnpm install
  2. pnpm dev
  3. open the browser
@9aoy 9aoy added the bug Something isn't working label Mar 21, 2023
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Mar 21, 2023
@9aoy 9aoy added this to the modern.js milestone Mar 21, 2023
@underfin underfin self-assigned this Mar 21, 2023
@underfin
Copy link
Collaborator

underfin commented Mar 21, 2023

Related webpack/webpack#15833, it should get more feedback from webpack community.

Here is wrokaround for this.

// rspack.config.js

{
        builtins: {
		define: {
			'import.meta.env && import.meta.env.MODE': "'development'"
		}
	},
}

@underfin underfin added C-workaround and removed bug Something isn't working C-workaround labels Mar 21, 2023
@hardfist
Copy link
Contributor

it seems webpack already supports import.meta.env.MODE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants