You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a .ts script in my project. It calls multiple dependencies in and outside the project.
One of them is a package (dep-a) whose code is an .mjs file.
This one, in turn, uses the default export from another package (dep-b) that is marked with type: "module", and the code is a .js file.
tsx doesn't treat dep-b correctly as an ES Module and wraps everything in a default export.
/Users/carlos.precioso/Developer/NewWork/tsx-test-case/dep-a/main.mjs:3
export const foo = bar();
^
TypeError: (0 , import_dep_b.default) is not a function
at bar (/Users/carlos.precioso/Developer/NewWork/tsx-test-case/dep-a/main.mjs:3:20)
at Object.<anonymous> (/Users/carlos.precioso/Developer/NewWork/tsx-test-case/dep-a/main.mjs:3:24)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Object.S (/Users/carlos.precioso/Developer/NewWork/tsx-test-case/node_modules/tsx/dist/cjs/index.cjs:1:1250)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at <anonymous> (/Users/carlos.precioso/Developer/NewWork/tsx-test-case/main.ts:1:21)
at Object.<anonymous> (/Users/carlos.precioso/Developer/NewWork/tsx-test-case/main.ts:3:16)
It's worth noting that changing the initial script's extension from .ts to .mts or .js works fine with tsx. Also changing the initial script from TypeScript to regular JavaScript and changing the extension to .mjs also works fine with regular Node without tsx.
Expected behavior
dep-a imports dep-b and uses its default export without any problem.
The original project has dep-a and dep-b as regular npm dependencies in node_modules, but StackBlitz doesn't store the contents, so I moved it to just regular folders with a package.json, because that still shows the error.
Version
v3.13.0
Node.js version
v18.18.0
Package manager
npm
Operating system
macOS
Contributions
I plan to open a pull request for this issue
I plan to make a financial contribution to this project
The text was updated successfully, but these errors were encountered:
I'm not sure, in that issue they are trying to import a CJS file from an ESM file. In my case the problem is in one ESM dependency trying to call another ESM dependency, and failing.
Problem
I created a
.ts
script in my project. It calls multiple dependencies in and outside the project.One of them is a package (
dep-a
) whose code is an.mjs
file.This one, in turn, uses the default export from another package (
dep-b
) that is marked withtype: "module"
, and the code is a.js
file.tsx
doesn't treatdep-b
correctly as an ES Module and wraps everything in a default export.Expected behavior
dep-a
importsdep-b
and uses its default export without any problem.Minimal reproduction URL
https://stackblitz.com/edit/node-c5szx5?file=main.ts&view=editor
Version
v3.13.0
Node.js version
v18.18.0
Package manager
npm
Operating system
macOS
Contributions
The text was updated successfully, but these errors were encountered: