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

package gets resolved as commonjs from an esm project #372

Closed
Tronikelis opened this issue Jun 20, 2023 · 4 comments · Fixed by #373
Closed

package gets resolved as commonjs from an esm project #372

Tronikelis opened this issue Jun 20, 2023 · 4 comments · Fixed by #373

Comments

@Tronikelis
Copy link

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:

Screenshot from the website

firefox_EuObXPe0Op

Thanks

@Andarist
Copy link
Owner

Could you try out the version from this PR: #373 ?

@Tronikelis
Copy link
Author

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

@Andarist
Copy link
Owner

🙈 I forgot to commit those two files. Could you try again now?

@Tronikelis
Copy link
Author

Tronikelis commented Jun 20, 2023

Now it builds successfully for me 🚀

Edit: tested on vite/next.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants