-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Cannot read property 'custom' of undefined #2598
Comments
Hello @rashagu. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by |
here is a minimal GitHub repository: https://github.com/rashagu/vite_test1 |
If it turns out that's a bug, I think I can help with working on it. ❤️ |
@Aslemammad I could reproduce the issue, it may end up being a problem upstream with umi-request. Maybe good to remove the outDir and base configs that are not needed for this repro. It would be great if you could dig into this and find where is the problem. Just in case it is not clear
Check the console for the issue. Thanks! |
@matias-capeletto Thanks Matias, I wanted to ask you about this, but you answered me earlier, which is great. I'll dig into it and work on it. |
This is useful, but it should not be the final solution
|
Doesn't seem to be fixing the issue for me |
I figured out the package in my app causing the same error is https://www.npmjs.com/package/twitch
anywhere so it's not tree-shaken and the build will fail silently with same symptoms. |
We debugged this a bit in Vite Land, and found that the problem is in an internal dependency: To reproduce, add that dependency and the generated build will have the error
This dependency has a ignore module for the browser for one of the files https://github.com/inspect-js/object-inspect/blob/master/package.json#L67, and that seems to be the problem (https://github.com/inspect-js/object-inspect/blob/master/util.inspect.js) For reference https://github.com/defunctzombie/package-browser-field-spec#ignore-a-module Looks like Vite has code to handle this already, but it may be malfunctioning. |
Great, it also works for me. I use |
I fixed this by replacing my usage of |
The issue is somehow related to having additional "." in |
Further investigation revealed that the issue is probably caused by vite not being able to handle the case where import is specified in package.json
And then required in the code omitting ".js" file extension:
P.S. |
Unfortunately this didn't work for one of my projects since |
You can just locate node_modules\object-inspect\index.js in your project and replace line 22 to:
There is probably better workaround solution with forking it and replacing dependency but I don't know how this works. |
You can use patch-package to make that fix! ☝️ |
npm uninstall qs |
HOW? |
Regarding #2598 (comment), the browser field absolutely is supposed to use node resolution. This is a bug with whatever is bundling the browser field incorrectly. |
@ljharb agreed that this is an issue in Vite. It looks like Vite only has basic support for the browser field, and it is having issues coping with ignoring a module. https://github.com/defunctzombie/package-browser-field-spec#ignore-a-module For reference, in case it is lost in the comments, Vite doesn't seem to support ignoring this module:
And it would be good if Vite can add support for this. |
@matias-capeletto my theory is that problem is not with vite not supporting "ignore a module" feature but with incorrect mapping of modules that have a "." in file name with browser fields due to
makes vite ignore the module correctly. |
If absolutely necessary, I'm willing to update the package to bypass the issue, but before doing that, I'd prefer to hear from a vite maintainer as to either when the proper fix will be deployed, or why it's difficult to do the proper fix. |
qs:issues ljharb/qs#406 I know the solution "dependencies": {
// qs < version 6.10
"qs": "6.9.6"
} |
@ljharb Vite v2.1.4 has been released with improved support for browser field resolution. There is no need to patch |
Thank you! |
Describe the bug
The development environment is fine, but the production environment reports an error
And I used umi-request
TypeError: Cannot read property 'custom' of undefined at index.2642e881.js:1
Reproduction
a minimal GitHub repository: https://github.com/rashagu/vite_test1
System Info
vite
version:2.1.2Logs (Optional if provided reproduction)
vite
orvite build
with the--debug
flag.The text was updated successfully, but these errors were encountered: