🐛 BUG: Cannot read property 'code' of undefined at Snowpack 3.8.0+
See original GitHub issueQuick checklist
- I am using the latest version of Snowpack and all plugins.
What package manager are you using?
yarn
What operating system are you using?
macOS
Describe the bug
Upon updating snowpack to any version above 3.8.0
, I receive the following error:
TypeError: Cannot read property 'code' of undefined
at FileBuilder.getProxy (/Users/negan/Projects/Firesquad/firesquad-app/node_modules/snowpack/lib/cjs/build/file-builder.js:267:48)
at loadUrl (/Users/negan/Projects/Firesquad/firesquad-app/node_modules/snowpack/lib/cjs/commands/dev.js:628:55)
at async handleRequest (/Users/negan/Projects/Firesquad/firesquad-app/node_modules/snowpack/lib/cjs/commands/dev.js:728:28)
[23:33:13] [snowpack] TypeError: Cannot read property 'code' of undefined
[23:33:13] [snowpack] [500] /_snowpack/link/packages/ui/styles.css.proxy.js
Looks to be caused by proxy style files, this even happens when disabling all plugins.
Steps to reproduce
yarn add snowpack@latest
snowpack dev
- Fails
Link to minimal reproducible example (optional)
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Cannot read property 'code' of undefined at Snowpack 3.8.0+ ...
I've ran into this issue with css/scss files before and it usually means the file is empty, adding an empty .root {} class...
Read more >"Cannot read property '$$' of undefined" in build : r/sveltejs
The page loads correctly but causes all links to not work, with the error "Cannot read property 'context' of undefined" from the same...
Read more >TypeError: Cannot read property 'data' of undefined
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >Cannot read properties of undefined' - JavaScript Debugging
Join Discord 👊 https://selftaught-dev.com/join-discord//r/SelfTaughtDev - https://www.reddit.com/r/selftaughtdevGet My Resume Template Free ...
Read more >How to Fix Uncaught TypeError - YouTube
Uncaught TypeError: Cannot read propertyIf you're a JavaScript developer, you've probably seen this error more than you care to admit.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When trying to fix this, it was also necessary to change the responseType to .woff2, not only the resourceType. But now I get a browser error:
So the root of the problem seems to me, that this asset should not be proxied as a .js anyway. It has more to do with the file-loader being used when importing a relative static file like so:
This shouldnt be rewritten as a proxied reference?
But when I run snowpack for production, it has the same problem. When using webpack, this works out-of-the-box.
@jacty I have a similar issue in a lerna managed monorepo, where one of my packages is importing a local .woff2 asset. The woff2 asset is in a prebuild step being copied to the /dist folder of that package.
Snowpack is trying to fetch a proxy for this asset (by adding
.proxy.js
to a static asset?):When I debug the getProxy line 269:
const code = this.resolvedOutput[type].code;
, because ofthis.resolvedOutput[type]
being undefined, this is because type was set to ‘.js’ and not ‘.woff2’?The FileBuilder.build didnt fail. resolvedOutput contains a key ‘.woff2’, with an object with a code field with the correct content.
When I change this line to
the file is being resolved correctly.
The root of this issue, seems to be that the resourceType of the asset, is wrongly being decided to be
.js
. I suppose this is because of the extension of the proxy that needs to be stripped of for static assets when deciding on fileType.https://github.com/snowpackjs/snowpack/blob/main/snowpack/src/commands/dev.ts#L624 the foundType is derived from the reqPath, instead of the resourcePath, where the
.proxy.js
suffix was already stripped off?This only is the case for assets inside a symlinked directory (monorepo setup) (https://github.com/snowpackjs/snowpack/blob/main/snowpack/src/commands/dev.ts#L551) because for all others the resourceType is being derived from the resourcePath instead of the req(uest)Path: https://github.com/snowpackjs/snowpack/blob/main/snowpack/src/commands/dev.ts#L645