Closed khaiquangnguyen closed 1 year ago
hello @khaiquangnguyen 👋 could you provide a reproduction repo?
Sure.
https://github.com/khaiquangnguyen/tsbelt-nodenext
Here is it.
npm run build
and then npm run start
to see the error.
So after a couple of testings, it only have issues with nodenext
module. both esnext
and node16
seems to work fine. This is a bit of an edge case but official node and typescript have recommended nodenext
as the path forward, so i think we should try to support this if possible.
I ran into the same issue today when using ts-belt
with ESM and TypeScript. I haven't been able to find a workaround yet.
same here
import { D } from '@mobily/ts-belt';
^
SyntaxError: Named export 'D' not found. The requested module '@mobily/ts-belt' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@mobily/ts-belt';
const { D } = pkg;
@mobily I can take a look at this if you are too busy at the moment.
@khaiquangnguyen @tgillus @Talent30 the issue has been fixed in v4.0.0-rc.1
🚀
@mobily That's awesome. I appreciate your work on this library.
First of all, I want to say that I really like ts-belt utilities and really wanted to make it work with my current project.
Issue:
module:nodenext
, ts-belt is resolved as a esm module and redirected todist/esm
folder. However, the files of this folder still have.js
extension and thepackage.json
does't containtype:module
option, which makes node assumes that it is trying to import a CommonJS module and try to resolve the import as such.SyntaxError: Cannot use import statement outside a module