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

Build Error: [rollup-plugin-dynamic-import-variables] Unexpected token #2330

Closed
2 tasks done
HenryWong-fe opened this issue Mar 2, 2021 · 18 comments
Closed
2 tasks done

Comments

@HenryWong-fe
Copy link

⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.

Describe the bug

can no build this project

Reproduction

https://github.com/HenryWong-fe/vite-project

System Info

  • vite version: ^2.0.0
  • Operating System: mac os 10.15.4
  • Node version: v14.15.1
  • Package manager (npm/yarn/pnpm) and version: npm 6.14.8

Logs (Optional if provided reproduction)

image

@softboy99
Copy link

Hi,
I encounter 'unknown variable dynamic import' error when build for production. However, it is ok when dev env. Is there any configuration needed for dynamic import? There are little about this in the doc

@HenryWong-fe
Copy link
Author

There are too few error messages to locate accurately。I found a related bug in issue, but it has been fixed,It's not clear what caused the build error。

@mdhelaluddin-ctg-bd
Copy link

Hi,
I encounter 'unknown variable dynamic import' error when build for production. However, it is ok when dev env. Is there any configuration needed for dynamic import? There are little about this in the doc

Did you solve this issue?

@softboy99
Copy link

softboy99 commented Mar 26, 2021

Hi,
I encounter 'unknown variable dynamic import' error when build for production. However, it is ok when dev env. Is there any configuration needed for dynamic import? There are little about this in the doc

Did you solve this issue?

Hi,
add "@rollup/plugin-dynamic-import-vars" to your devdependencies and configure it in your vite.config.js, fix it.

vite.config:

build: {
rollupOptions: {
plugins: [
dynamicImportVars()
],
},
},

@mdhelaluddin-ctg-bd
Copy link

Hi,
I encounter 'unknown variable dynamic import' error when build for production. However, it is ok when dev env. Is there any configuration needed for dynamic import? There are little about this in the doc

Did you solve this issue?

Hi,
add "@rollup/plugin-dynamic-import-vars" to your devdependencies and configure it in your vite.config.js, fix it.

vite.config:

build: {
rollupOptions: {
plugins: [
dynamicImportVars()
],
},
},

Added in vite config file as you have suggested but no luck when deployed to the server. It's giving the same error! I have attached both code and error. Please check and suggest if possible. Thanks

image

image

@patak-dev
Copy link
Member

@rollup/plugin-dynamic-import-vars is already included in Vite. The repro is too big to test a particular issue and it is currently outdated. Please open a new issue with a minimal reproduction against the latest Vite version if you still have a problem.

@stefanvanherwijnen
Copy link
Contributor

This is possibly caused because you did not load the vue plugin in vite:
https://github.com/vitejs/vite/tree/main/packages/plugin-vue

My guess is that without it the SFC is not parsed correctly and top level imports are wrongly handled as dynamic imports, thus causing the error. Loading the plugin fixed the problem for me.

@xinyao27
Copy link

I ran into the same problem, but the difference is that I ran the react app.

image

@nukefusion
Copy link

This can also happen if you are using Typescript and building with "vue-tsc --noEmit && vite build" but you've somehow managed to emit a JS copy of vite.config.ts to disk. Check for vite.config.js, delete and rerun.

@CocaColf
Copy link

Hi,
I encounter 'unknown variable dynamic import' error when build for production. However, it is ok when dev env. Is there any configuration needed for dynamic import? There are little about this in the doc

Did you solve this issue?

Hi,
add "@rollup/plugin-dynamic-import-vars" to your devdependencies and configure it in your vite.config.js, fix it.
vite.config:
build: {
rollupOptions: {
plugins: [
dynamicImportVars()
],
},
},

Added in vite config file as you have suggested but no luck when deployed to the server. It's giving the same error! I have attached both code and error. Please check and suggest if possible. Thanks

image

image

Hi,I have the same error and the suggestions above doesn't work for me. Did you fixed it?

@DhvanilPatel
Copy link

I'm facing the same issue too while running npm run build

@LauJon
Copy link

LauJon commented May 26, 2021

I'm facing the same issue too while running npm run build

@callmeberzerker
Copy link

callmeberzerker commented May 27, 2021

Same issue - has anyone found a solution?

It happens when I upgrade from vite@2.2.1 -> vite@2.3.4

@robertvansteen
Copy link

robertvansteen commented May 27, 2021

I'm facing this issue as well.

const page = await import(`./pages/${name}.tsx`);

Files that are directly in the pages directly are included, but nested ones e.g. pages/user/profile.tsx are not.

Edit: this seems a limitation of rollup-plugin-dynamic-import-variables as mentioned in the readme.

@BirkhoffLee
Copy link

Same here on latest Vite while running npm run build.

@nstuyvesant
Copy link

nstuyvesant commented Jun 13, 2021

If you happen to be running into this with Svelte, a workaround was suggested here. I was getting build errors on .svelte pages that have a style tag and use an environmental variable via import.meta.env.

@collinsuzebu
Copy link

For me, I mistakenly named my file .js instead of .jsx. It was kind enough to tell me the file causing the error.

@github-actions
Copy link

This issue has been locked since it has been closed for more than 14 days.

If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2021
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