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

Unexpected token if object contains process.env #3701

Closed
6 tasks done
cawa-93 opened this issue Jun 7, 2021 · 2 comments · Fixed by #3703
Closed
6 tasks done

Unexpected token if object contains process.env #3701

cawa-93 opened this issue Jun 7, 2021 · 2 comments · Fixed by #3703

Comments

@cawa-93
Copy link
Contributor

cawa-93 commented Jun 7, 2021

Describe the bug

Script parsing chash, on the line of this type:

<sonething>.process.env.<sonething>

Reproduction

  1. Setup vanilla Vite project
  2. Put to main.js:
     const foo = {
         process: {env: {FOO: 'BAR'}},
     };
    
     console.log(foo.process.env.FOO);
  3. Run build: npm run build
  4. I got error:
    [rollup-plugin-dynamic-import-variables] Unexpected token (5:16)
    file: .../main.js:5:16
    error during build:
    SyntaxError: Unexpected token

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
    Memory: 4.51 GB / 15.42 GB
  Binaries:
    Node: 16.3.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.15.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.423.0), Chromium (91.0.864.41)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    vite: ^2.3.5 => 2.3.6

Used package manager: npm

Logs

$ npm run build

> build
> vite build

vite v2.3.6 building for production...
 1 modules transformed.
[rollup-plugin-dynamic-import-variables] Unexpected token (5:16)
file: C:/Users/kozac/Dev/vite-issue-with-global-syntax/main.js:5:16
error during build:
SyntaxError: Unexpected token (5:16)
    at Parser.pp$4.raise (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:16748:13)
    at Parser.pp.unexpected (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:14258:8)
    at Parser.pp$3.parseIdent (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:16679:10)
    at Parser.pp$3.parseSubscript (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15970:28)
    at Parser.pp$3.parseSubscripts (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15939:24)
    at Parser.pp$3.parseExprSubscripts (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15923:21)
    at Parser.pp$3.parseMaybeUnary (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15886:17)
    at Parser.pp$3.parseExprOps (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15819:19)
    at Parser.pp$3.parseMaybeConditional (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15802:19)
    at Parser.pp$3.parseMaybeAssign (C:\Users\kozac\Dev\vite-issue-with-global-syntax\node_modules\rollup\dist\shared\rollup.js:15770:19)

Before submitting the issue, please make sure you do the following

@cawa-93
Copy link
Contributor Author

cawa-93 commented Jun 7, 2021

It seems the cause of the problem in the definePlugin plugin. At the parsing stage, the rollup-plugin-dynamic-import-variables receives the following code:

const foo = {
	process: {env: {FOO: 'BAR'}},
};

console.log(foo.({}).FOO);

@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 15, 2021
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