Andarist / react-textarea-autosize

<textarea /> component for React which grows with content

Home Page:http://andarist.github.io/react-textarea-autosize/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

Screenshot from the website

firefox_EuObXPe0Op

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