-
Notifications
You must be signed in to change notification settings - Fork 922
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
[BUG] sowpack bundle build generate import statement for images and json files #3109
Comments
You can wrap your json object into a .ts or .js file. {
"foo": "bar"
} Use a .ts/.js file with export: export default {
"foo": "bar"
} |
@BogdanDarius Note that as mentioned the issue is also with image Both were working in previous version of snowpack actually |
Yes I know. It was just a quick workaround. |
Thanks for reporting. Also seeing similar issues with json and images. Hopefully we'll find a fix soon! With previous version (3.0.11), it retains the construct of // dist/logo.svg.proxy.js
var logo_svg_proxy_default = "/dist/logo.svg"; In 3.2.2, the images are being imported directly in the built js files. // build/components/Logo.js
import logo from "../img/logo.svg"; |
As this is the last blocker for our migration, I spent sometime digging this. The following refactor also suspected this regression (I left a comment at the particular line): |
One work around is to create a Snowpack plugin that reset the resolveProxyImports in a JS task: module.exports = function config() {
return {
name: 'snowpack-config-resolveProxyImports-plugin',
config(config) {
setTimeout(() => {
config.buildOptions.resolveProxyImports = true
})
},
};
} Will also propose a quick pull request to fix this. |
The line I removed set resolveProxyImports to false for bundled builds and cause image and json files to be imported directly instead of through proxy imports. This change fixes: [BUG] sowpack bundle build generate import statement for images and json files FredKSchott#3109 FredKSchott#3109
The line I removed set resolveProxyImports to false for bundled builds and cause image and json files to be imported directly instead of through proxy imports. This change fixes: [BUG] sowpack bundle build generate import statement for images and json files FredKSchott#3109 FredKSchott#3109
Thanks for raising. Thanks to the wonderful @lukejacksonn, he recently updated our Snowpack test suite and it is much, much easier to write tests for! 🎉 If someone on this issue can open a PR with a failing test that captures the behavior, I’d be happy to suggest a fix for it. |
Hi @drwpow, thanks for looking into this. This can be reproduced with a basic snowpack template app.
If you turn on optimize.bundle to true in snowpack.config.js, and try to open build/index.html in the browser (I use http-server to serve the build directory, but any web server works)
you should be able to see the error:
|
Any update? I am stuck on Snowpack 3.0.13 because of this bug and am unable to upgrade. |
Any update? Still can't import any JSON file. |
Experienced this issue in 3.8.8 when importing |
to hopefully get around FredKSchott/snowpack#3109 branch:
Any update on this? |
Bug Report Quick Checklist
Describe the bug
[BUG] sowpack build generate import statement for json file and image
This result in error loading it in browser :
for images :
for json files:
To Reproduce
Reproduction repo : https://github.com/bug-reproduction/snowpack-import-files
yarn && yarn build && yarn serve
Expected behavior
Expect to be able to load image and json when imported in source.
This work in dev mode,
The text was updated successfully, but these errors were encountered: