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

The config define may cause error with ?raw #10140

Closed
7 tasks done
Tsuk1ko opened this issue Sep 16, 2022 · 1 comment
Closed
7 tasks done

The config define may cause error with ?raw #10140

Tsuk1ko opened this issue Sep 16, 2022 · 1 comment

Comments

@Tsuk1ko
Copy link

Tsuk1ko commented Sep 16, 2022

Describe the bug

If a js file contains strings which are defined in the define config, such as process.env.NODE_ENV, errors will occur when import it with ?raw.

Uncaught SyntaxError: Unexpected identifier 'development' (at test.js?raw:1:33)

The origin js file

export default process.env.NODE_ENV;

After ?raw processing (http://127.0.0.1:5173/src/test.js?raw)

export default "export default "development";\r\n"

It looks like the string replacement happens after the ?raw processing causing this error.

Reproduction

https://github.com/Tsuk1ko/vite-define-with-raw-loader-issue

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 Intel(R) Core(TM) i9-9900KF CPU @ 3.60GHz  
    Memory: 17.00 GB / 31.92 GB
  Binaries:
    Node: 16.17.0 - D:\n\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.18.0 - ~\AppData\Roaming\npm\npm.CMD
  Browsers:
    Chrome: 105.0.5195.126
    Edge: Spartan (44.19041.1266.0), Chromium (105.0.1343.33)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-vue: ^3.1.0 => 3.1.0 
    vite: ^3.1.1 => 3.1.1

Used Package Manager

yarn

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Sep 17, 2022

Duplicate of #9829 and #9790

There's a PR to fix this at #9791

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 2, 2022
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

2 participants