-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Add exports field to package.json in order to support moduleResolution node12/nodenext #1726
Comments
The above suggestion is mostly correct, but there's a caveat with the file extensions. Depending on the the value of the To make Node happy we have to either:
There's also the option of dropping CJS completely, adding |
I don't think the suggestion by @andreavaccari is currently applicable, since My suggestion would allow a user using ESM to load the ES6 version of Though, to be fair, I don't think there is much of a difference between ES6 and ESM files. I believe it's just the internal import statements requiring extensions. And the Edit: |
Updated my test fork to 2.12.3. (viell-dev/fp-ts) Also I saw that #1525 also talks about |
@viell-dev in v3 I'm using {
"exports": {
".": {
"require": "./lib/index.js",
"import": "./es6/index.js"
},
"./*": {
"require": "./lib/*.js",
"import": "./es6/*.js"
}
},
"types": "index.d.ts",
"typesVersions": {
"*": {
"*": [
"./types/*"
]
}
},
"sideEffects": false
} So for backwards-compatibility in v2 would be {
"exports": {
".": {
"require": "./lib/index.js",
"import": "./es6/index.js"
},
"./*": {
"require": "./lib/*.js",
"import": "./es6/*.js"
},
"./es6/*": {
"import": "./es6/*.js"
},
"./lib/*": {
"require": "./lib/*.js"
}
},
"types": "index.d.ts",
"typesVersions": {
"*": {
"*": [
"./types/*"
]
}
},
"sideEffects": false
} |
Hi all, I've just released https://github.com/gcanti/fp-ts/releases/tag/2.13.0-rc.2 (install with |
@gcanti I tried it and I'm getting: "Could not find a declaration file for module 'fp-ts/Option'." After testing locally I've concluded that you will need to have the e.g. {
"exports": {
".": {
"require": "./lib/index.js",
"import": "./es6/index.js",
"types": "./types/index.d.ts"
},
"./*": {
"require": "./lib/*.js",
"import": "./es6/*.js",
"types": "./types/*.d.ts"
},
"./es6/*": {
"import": "./es6/*.js",
"types": "./types/*.d.ts"
},
"./lib/*": {
"require": "./lib/*.js",
"types": "./types/*.d.ts"
}
},
} |
Ok, thank you, going to release |
done |
Looks great. 👍🏻 |
Nice, thank you for your help @viell-dev |
I saw that the changes got reverted in |
🚀 Feature request
Current Behavior
When using
"moduleResolution": "NodeNext",
in your tsconfig it expects an"exports": ...
field in package.json in order to resolve the package.Otherwise:
Cannot find module 'fp-ts/Either' or its corresponding type declarations.ts(2307)
Desired Behavior
Importing to work.
Suggested Solution
Shove this in package.json:
Tested it locally by putting that above
"main"
like in the example as seen in the TS 4.7 link below, seems to do the job.The
"./es6/*"
or"./lib/*"
parts are only needed for backwards-compatibility with the old import paths.Who does this impact? Who is this for?
People wanting to use
fp-ts
with the new ECMAScript Module Support added with TypeScript 4.7.Describe alternatives you've considered
Not using the new ECMAScript Module support feature. 🤷♂️
Most NPM packages aren't updated to support this yet.
Additional context
TS 4.7 link: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#esm-nodejs
Node.js link: https://nodejs.org/api/packages.html#package-entry-points
Your environment
The text was updated successfully, but these errors were encountered: