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

[rollup-plugin-dynamic-import-variables] Unexpected token #5278

Closed
7 tasks done
johnnybenson opened this issue Oct 13, 2021 · 0 comments · Fixed by #5515
Closed
7 tasks done

[rollup-plugin-dynamic-import-variables] Unexpected token #5278

johnnybenson opened this issue Oct 13, 2021 · 0 comments · Fixed by #5515

Comments

@johnnybenson
Copy link

johnnybenson commented Oct 13, 2021

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 👇

Related:
#5247
#2605

Reproduction

https://github.com/johnnybenson/vitejs-bug-repro-define

$ git clone https://github.com/johnnybenson/vitejs-bug-repro-define
$ yarn install 
$ yarn build --debug

Observe 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.7

Used 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-bug

Variations

  • Tried with/without JSON.stringify around boolean globals
  • Tried esbuild and terser for minification
  • Tried with/without tsc preceding build

Validations

@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant