package gets resolved as commonjs from an esm project
Tronikelis opened this issue Β· comments
Hey, I recently stumbled upon some weird behavior while using another library that uses your package, the library is https://github.com/nextui-org/nextui v2
I am kinda out of options, cause I am struggling to figure this out myself
I am using ts + vite + vite-plugin-ssr with default configs
But got the same behavior using next.js as well
While bundling the project I got an error that Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
I created an issue for this nextui-org/nextui#1160
The gist of it is that your package gets resolved as commonjs from an esm project (vite uses esm by default either way I think) and then the cjs exports the component as module.exports.default =
but esm treats default exports from commonjs as module.exports =
not as module.exports.default =
So when nextui-org imports your package it gets imported as {default: ..component..}
which is not a component and it fails
More info nextui-org/nextui#1160
I am not sure if this is because of a bad vite config, but I don't think so, because I checked your package with https://arethetypeswrong.github.io/?p=react-textarea-autosize%408.4.1 and just as I thought node16-esm
resolves your package to cjs:
Thanks
Could you try out the version from this PR: #373 ?
I got an error when trying to build it:
π info building bundles!
π error react-textarea-autosize [Error: Could not load X:\coding\coding\react-textarea-autosize\src\resolved-conditions\false.ts: ENOENT: no such file or directory, open 'X:\coding\coding\react-textarea-autosize\src\resolved-conditions\false.ts'] {
π error react-textarea-autosize errno: -4058,
π error react-textarea-autosize code: 'PLUGIN_ERROR',
π error react-textarea-autosize syscall: 'open',
π error react-textarea-autosize path: 'X:\\coding\\coding\\react-textarea-autosize\\src\\resolved-conditions\\false.ts',
π error react-textarea-autosize pluginCode: 'ENOENT',
π error react-textarea-autosize plugin: 'resolve-errors',
π error react-textarea-autosize hook: 'resolveId',
π error react-textarea-autosize watchFiles: [
π error react-textarea-autosize 'X:\\coding\\coding\\react-textarea-autosize\\src\\index.tsx',
π error react-textarea-autosize 'X:\\coding\\coding\\react-textarea-autosize\\src\\resolved-conditions\\false.ts'
π error react-textarea-autosize ]
π error react-textarea-autosize }
π info If you want to learn more about the above error, check https://preconstruct.tools/errors
π info If the error is not there and you want to learn more about it, open an issue at https://github.com/preconstruct/preconstruct/issues/new
π I forgot to commit those two files. Could you try again now?
Now it builds successfully for me π
Edit: tested on vite/next.js