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
Error in dev mode only (works in prod) with json import #4897
Comments
Bug in esbuild json loader. It shouldn't export these top-level properties that aren't valid js identifiers. |
Reported at evanw/esbuild#1598 |
This is not a problem with esbuild because the output is valid JavaScript. It's just using the new arbitrary module namespace identifier names syntax feature (supported in recent versions of Chrome, Firefox, Safari, and Node). You need to set esbuild's target setting correctly if you need to support older JavaScript VMs that can't parse newer syntax. Then esbuild won't generate these exports. Either that or Vite's import analysis pass needs to be updated to support this new import/export syntax. |
Got it. Thanks for the information. I think we are now pending If anyone's interested in implementing this feature, you can take the corresponding commits to support string exports in |
Hello @vladitasev. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! |
Describe the bug
Hello, I am part of the UI5 Web Components team (https://sap.github.io/ui5-webcomponents/) and we're recommending
vitejs
as the to-go bundler for people looking to start using our web components. However, one of our demo apps fails in dev mode when we try to demonstrate the usage of our.json
-based assets (in this case CLDR data).After importing a
.json
file I get the following error:[plugin:vite:import-analysis] Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
This works perfectly fine in prod mode (
npm run build
), and only occurs fornpm run dev
.Reproduction
Create an empty project with the vanilla template:
npm init vite@latest my-test-app -- --template vanilla
npm i
Add
@ui5/webcomponents
as a dependencynpm i @ui5/webcomponents
Import the following 2 modules in the
main.js
file:index.html
file, right after the body tag:npm run dev
You will get the "Invalid JS syntax" error.
Now run the project in prod mode
npm run build
npm run serve
This works well and you can see the date picker on your page.
System Info
System: OS: macOS 11.5.2 CPU: (8) x64 Apple M1 Memory: 36.10 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.7.0 - /usr/local/bin/npm Browsers: Chrome: 93.0.4577.63 Safari: 14.1.2 npmPackages: vite: ^2.5.4 => 2.5.6
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: