Open felix98765 opened 1 year ago
This happens because tsx converts the ESM file to CommonJS (since your package has a CommonJS type).
That means your import
here:
import { Auth } from '@auth/core'
Is converted to a require
, and given to Node.js to resolve:
const { Auth } = require('@auth/core')
Since to Node.js, it's a require()
, it's unable to resolve the entry-point because it only supports types
and import
:
".": {
"types": "./index.d.ts",
"import": "./index.js"
},
Thanks. Do this mean I can't use ESM dependencies with tsx when my project is itself a CommonJS package?
I ended up rebundling the @auth/core
as a CommonJS package.
tsx supports loading ESM from CommonJS. Just not the exports map configuration in @auth/core
.
Leaving this open as a feature request
As an example of where something like this might be necessary, some packages are not only supporting the import
condition.
For example, @octokit/core: https://github.com/octokit/core.js/blob/9ab61fa16e8350c29af790869abd2028893a5126/scripts/build.mjs#L60-L65
Bug description
What did you do? (Provide reproduction code in next section)
Import a ES module with a main export (https://github.com/nextauthjs/next-auth/blob/b96f01319c751c7d62433c24fdb9f3f8f1e572c1/packages/core/package.json#L36).
What did you expect to happen?
Import successfully.
What happened instead?
An error throwed.
Do you have an error stack-trace or screenshots?
Reproduction
https://github.com/felix98765/tsx-no-exports-main-defined
Environment
Can you work on a fix?