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

Production environment library method does not exist #9061

Closed
7 tasks done
huzedong2015 opened this issue Jul 13, 2022 · 9 comments
Closed
7 tasks done

Production environment library method does not exist #9061

huzedong2015 opened this issue Jul 13, 2022 · 9 comments
Labels
feat: commonjs @rollup/plugin-commonjs issue inconsistency Inconsistency between dev & build p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@huzedong2015
Copy link

Describe the bug

Production environment htmldiff execute function is undefined

Reproduction

https://stackblitz.com/edit/vitejs-vite-pisuhy?file=main.js

System Info

null

Used Package Manager

pnpm

Logs

$ vite build
$ cd dist
$ pnpx live-server

Validations

@huzedong2015
Copy link
Author

huzedong2015 commented Jul 13, 2022

Code

import htmlDiff from "htmldiff-js";

development

htmlDiff is class v

production environment

htmlDiff is { default: class v, __esModule: true }

@huzedong2015
Copy link
Author

huzedong2015 commented Jul 13, 2022

Check the @rollup/plugin-commonjs document. It should be possible to configure the defaultismoduleexports option to false, but vite.config. js build. Commonjsoptions does not have this configuration

@huzedong2015
Copy link
Author

huzedong2015 commented Jul 13, 2022

I found that vite config. js build. commonjsOptions. Defaultismoduleexports is set to false, and the production environment can run normally,But I don't know if it will bring other problems

@bluwy bluwy added the inconsistency Inconsistency between dev & build label Jul 14, 2022
@sapphi-red sapphi-red added the feat: commonjs @rollup/plugin-commonjs issue label Aug 2, 2022
@davbrito
Copy link

davbrito commented Aug 2, 2022

The workaround that I did for this issue was to do something like:

import $htmlDiff from "htmldiff-js";
const htmlDiff = $htmlDiff.default || htmlDiff

But it feels a little bit tricky. So I hope you can solve this problem soon.

@huzedong2015
Copy link
Author

The workaround that I did for this issue was to do something like:

import $htmlDiff from "htmldiff-js";
const htmlDiff = $htmlDiff.default || htmlDiff

But it feels a little bit tricky. So I hope you can solve this problem soon.

I think this can only be used as an emergency measure, which should be handled by the plug-in to keep the dev and pro environments consistent

@Young6-me
Copy link

Other dependencies I also encountered this similar problem

@AmyLoveLife
Copy link

I have the same situation,please solve it soon

@chocking
Copy link

chocking commented Sep 2, 2022

+1, Occured this when using lib mode for product build, and my module imports a commonJS module meanwhile.

@bluwy
Copy link
Member

bluwy commented Oct 29, 2023

I can't reproduce this anymore with Vite 4.5.0. It might be fixed the same way as #2139 (comment). In dev and prod, I'm getting the class directly. Closing as fixed.

@bluwy bluwy closed this as completed Oct 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: commonjs @rollup/plugin-commonjs issue inconsistency Inconsistency between dev & build p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

No branches or pull requests

7 participants