-
Notifications
You must be signed in to change notification settings - Fork 11
Weird CJS module hack is bombing Rollup builds #19
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
Comments
Details in JS-DevTools/ono#19, It's fixed in JS-DevTools/ono#20 This package is not maintained but it's depended on by swagger-parser
Running into the same issue — as a not-so-great workaround, I used the import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import { defineConfig } from 'rollup';
export default defineConfig({
input: 'input.js',
output: { file: 'output.cjs', format: 'cjs' },
plugins: [
commonjs(),
json(),
nodeResolve({ preferBuiltins: true }),
replace({
delimiters: ['', ''],
preventAssignment: true,
values: {
'if (typeof module === "object" && typeof module.exports === "object") {':
'if (typeof module === "object" && typeof module.exports === "object" && typeof module.exports.default === "object") {',
},
}),
],
}); |
As far as I can see, this commonjs "hack" does not belong in the esm version of the package build. Thats why that code fails. If you force using the cjs version of the package, the error disappears. Its ugly but it works. |
ono/src/index.ts
Lines 10 to 13 in a1fa89a
This code block is bombing my rollup build. Not caught during build. This code makes it into the bundle, and then it fails on runtime startup.
module.exports.default
is undefined and is killing the build.I found this by preserving the modules from Rollup so I could get a good stacktrace to the code.
I found if i do this it makes it past this part:
The text was updated successfully, but these errors were encountered: