-
-
Notifications
You must be signed in to change notification settings - Fork 8k
[rollup-plugin-dynamic-import-variables] Unexpected token #5278
Copy link
Copy link
Closed
Labels
Description
Describe the bug
Some part of production build or minification breaks globals set in config.define.
I have the minimal reproduction of the issue linked below 👇
Reproduction
$ git clone https://github.com/johnnybenson/vitejs-bug-repro-define
$ yarn install
$ yarn build --debugObserve that the values are set in config.
The build fails with the following error:
vite v2.6.7 building for production...
✓ 2 modules transformed.
[rollup-plugin-dynamic-import-variables] Unexpected token (12:16)
file: /Users/johnny/Sites/vite-define-bug/src/index.tsx:12:16
error during build:
SyntaxError: Unexpected token (12:16)
at Parser.pp$5.raise (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19495:13)
at Parser.pp.unexpected (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:16820:8)
at Parser.pp$4.parsePropertyValue (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19216:17)
at Parser.pp$4.parseProperty (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19165:8)
at Parser.pp$4.parseObj (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19111:21)
at Parser.pp$4.parseExprAtom (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18846:17)
at Parser.pp$4.parseExprSubscripts (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18662:19)
at Parser.pp$4.parseMaybeUnary (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18628:17)
at Parser.pp$4.parseExprOps (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18561:19)
at Parser.pp$4.parseMaybeConditional (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18544:19)
error Command failed with exit code 1.System Info
System:
OS: macOS 11.6
CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
Memory: 3.07 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.18.0 - ~/.nvm/versions/node/v14.18.0/bin/node
Yarn: 1.22.15 - /usr/local/bin/yarn
npm: 7.24.2 - ~/.nvm/versions/node/v14.18.0/bin/npm
Browsers:
Chrome: 94.0.4606.81
Safari: 15.0
npmPackages:
@vitejs/plugin-react: ^1.0.4 => 1.0.4
vite: ^2.6.7 => 2.6.7Used Package Manager
yarn
Logs
➜ vite-define-bug yarn build --debug
yarn run v1.22.15
warning package.json: No license field
$ tsc && vite build --debug
vite:config bundled config file loaded in 107.84ms +0ms
[dotenv][DEBUG] did not match key and value when parsing line 2:
vite:config using resolved config: {
vite:config define: {
vite:config __APP_VERSION__: '"0.0.0"',
vite:config __APP_ENV__: '"production"',
vite:config __DEV__: 'false',
vite:config __PROD__: 'true',
vite:config __TEST__: 'false'
vite:config },
vite:config plugins: [
vite:config 'alias',
vite:config 'vite:tsconfig-paths',
vite:config 'vite:react-babel',
vite:config 'vite:react-refresh',
vite:config 'vite:react-jsx',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-script-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:build-html',
vite:config 'commonjs',
vite:config 'vite:data-uri',
vite:config 'rollup-plugin-dynamic-import-variables',
vite:config 'vite:asset-import-meta-url',
vite:config 'vite:build-import-analysis',
vite:config 'vite:esbuild-transpile',
vite:config 'vite:reporter',
vite:config 'vite:load-fallback'
vite:config ],
vite:config build: {
vite:config target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config polyfillModulePreload: true,
vite:config outDir: 'dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config sourcemap: false,
vite:config rollupOptions: {},
vite:config minify: 'esbuild',
vite:config terserOptions: {},
vite:config write: true,
vite:config emptyOutDir: null,
vite:config manifest: false,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false,
vite:config reportCompressedSize: true,
vite:config chunkSizeWarningLimit: 500,
vite:config watch: null,
vite:config commonjsOptions: { include: [Array], extensions: [Array] },
vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
vite:config },
vite:config resolve: { dedupe: [ 'react', 'react-dom' ], alias: [ [Object], [Object] ] },
vite:config optimizeDeps: {
vite:config include: [ 'react/jsx-dev-runtime' ],
vite:config esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
vite:config },
vite:config configFile: '/Users/johnny/Sites/vite-define-bug/vite.config.ts',
vite:config configFileDependencies: [ 'vite.config.ts' ],
vite:config inlineConfig: {
vite:config root: undefined,
vite:config base: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config build: {}
vite:config },
vite:config root: '/Users/johnny/Sites/vite-define-bug',
vite:config base: '/',
vite:config publicDir: '/Users/johnny/Sites/vite-define-bug/public',
vite:config cacheDir: '/Users/johnny/Sites/vite-define-bug/node_modules/.vite',
vite:config command: 'build',
vite:config mode: 'production',
vite:config isProduction: true,
vite:config server: { fs: { strict: undefined, allow: [Array] } },
vite:config env: {
vite:config VITE_TEST: 'okcool',
vite:config BASE_URL: '/',
vite:config MODE: 'production',
vite:config DEV: false,
vite:config PROD: true
vite:config },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config hasWarned: false,
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config warnOnce: [Function: warnOnce],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen],
vite:config hasErrorLogged: [Function: hasErrorLogged]
vite:config },
vite:config createResolver: [Function: createResolver]
vite:config } +9ms
vite v2.6.7 building for production...
✓ 2 modules transformed.
[rollup-plugin-dynamic-import-variables] Unexpected token (12:16)
file: /Users/johnny/Sites/vite-define-bug/src/index.tsx:12:16
error during build:
SyntaxError: Unexpected token (12:16)
at Parser.pp$5.raise (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19495:13)
at Parser.pp.unexpected (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:16820:8)
at Parser.pp$4.parsePropertyValue (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19216:17)
at Parser.pp$4.parseProperty (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19165:8)
at Parser.pp$4.parseObj (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:19111:21)
at Parser.pp$4.parseExprAtom (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18846:17)
at Parser.pp$4.parseExprSubscripts (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18662:19)
at Parser.pp$4.parseMaybeUnary (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18628:17)
at Parser.pp$4.parseExprOps (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18561:19)
at Parser.pp$4.parseMaybeConditional (/Users/johnny/Sites/vite-define-bug/node_modules/rollup/dist/shared/rollup.js:18544:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜ vite-define-bugVariations
- Tried with/without
JSON.stringifyaround boolean globals - Tried
esbuildandterserfor minification - Tried with/without
tscpreceding build
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable