Replies: 1 comment 1 reply
-
We had a similar problem. In our case it came from feathers. This problem only occurs in the production build as it uses rollup to bundle and the dev-server is not. We finally fixed it for now by following this rollup issue: rollup/rollup/issues/2332. We now use import replace from '@rollup/plugin-replace';
import { defineConfig } from 'vite';
const config = defineConfig({
plugins: [
// ...
replace({
'Object.defineProperty(exports, "__esModule", { value: true });':
'Object.defineProperty(exports || {}, "__esModule", { value: true });',
delimiters: ['\n', '\n'],
}),
],
});
export default config;
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Some background. I'm trying to upgrade my frontend build system from parcel to Vite. The project is written in TypeScript. Running the dev server everything works great. But when I build using
npx vite build
, in the browser I get the errorUncaught ReferenceError: exports is not defined
.So far I've narrowed the issue to something outputting
Object.defineProperty(exports,"__esModule",{value:!0});
when it shouldn't.My tsconfig looks like this:
And my vite.config.js looks like this:
Based on these configurations, I believe output should be emitting ES Module syntax only. And yet
Object.defineProperty(exports,"__esModule",{value:!0});
is still produced. My prime suspect is currently esbuild as when I runtsc
directly, it doesn't produce any instances ofObject.defineProperty(exports
and correctly uses ES Module syntax.I've been scratching my head at this for awhile. But haven't found a solution. Any help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions