ts-loader: Module not found for TypeScript 4.7
Expected Behaviour
Able to bundle.
Actual Behaviour
errors such as:
Module not found: Error: Can't resolve './tersible.js'
Steps to Reproduce the Problem
In TypeScript 4.7, the NodeNext
module resolution requires the source code to specify the extension as .js
.
e.g.:
// index.ts
export * from './tersible.js' // for `tersible.ts`
For ts-jest
on the jest
side,
it solves that by doing a transformation:
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
Maybe something similar is needed? Would be great to add a section in the readme specifically for that.
Location of a Minimal Repository that Demonstrates the Issue.
Not a minimal repo, but here is an example: https://github.com/unional/tersify.
Run yarn bundle
in the repo
š·
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 54 (51 by maintainers)
Commits related to this issue
- fix: build working dist https://github.com/TypeStrong/ts-loader/issues/1463 `transpileOnly: true` doesn't work `tsconfig.cjs.json` doesn't work Use `NormalModuleReplacementPlugin` as workaround — committed to unional/tersify by unional 2 years ago
- fix: build working dist https://github.com/TypeStrong/ts-loader/issues/1463 `transpileOnly: true` doesn't work `tsconfig.cjs.json` doesn't work Use `NormalModuleReplacementPlugin` as workaround — committed to unional/tersify by unional 2 years ago
- fix: build working dist https://github.com/TypeStrong/ts-loader/issues/1463 `transpileOnly: true` doesn't work `tsconfig.cjs.json` doesn't work Use `NormalModuleReplacementPlugin` as workaround — committed to unional/tersify by unional 2 years ago
- fix: build working dist https://github.com/TypeStrong/ts-loader/issues/1463 `transpileOnly: true` doesn't work `tsconfig.cjs.json` doesn't work Use `NormalModuleReplacementPlugin` as workaround — committed to unional/tersify by unional 2 years ago
hm, why donāt use https://webpack.js.org/configuration/resolve/#resolveextensionalias? I think it will work
https://github.com/microsoft/TypeScript/issues/49083#issuecomment-1200999574
š
https://github.com/justland/just-web/pull/58
One update. After I add the
cjs/package.json
workaround, at least the CommonJS side resolution is working fine. Itās not directly related to this issue, but it shows that having due-export (CJS + ESM/NodeNext) able to work at the end application.I have published
color-map
with a few variations to test this:main
,module
,jsnext:main
: (https://github.com/unional/color-map/blob/v1.1.4/package.json)esnext
and module resolutionnode
(https://github.com/unional/color-map/blob/v2.0.0/tsconfig.esm.json)exports.require
(https://github.com/unional/color-map/blob/v2.0.2/package.json)upgrade to 4.7.3 (including test pack) complete
#1477 is the PR for that.
https://github.com/TypeStrong/ts-loader/issues/1464
It looks like the npm that ships with node 18 had some breaking changes. We use yarn 1 for ts-loader anyway, so Iād advise sticking with that
š¤£ thatās why. Only running comparison tests on Windows. I was running
yarn test
, i.e. also runningexecution-tests
I see. I can take a look at it. š
Sounds good - when you get to it, feel free to stick up a work in progress PR with broken tests if needs be. Will be happy to pair on this
NP. That explains all those nice pics. š·
Yeah, I can give it a shot. But need to handle a few things first. Will see if I can get to it. š
Roughly the three major bits of NodeNext / mts / cts support in ts-node were:
Replace nodeās resolver with one that checks what I call āalternative file extensions.ā Every time nodeās resolver would check for
foo.js
, also check for the alternatives:foo.ts
,foo.tsx
,foo.jsx
Teach transpiler codepaths to emit Typescriptās 2x new flavors of module:
import foo = require('foo')
statements automatically usecreateRequire
to gin up arequire
functionts.transpileModule
does not expose this functionality; cannot be usedTeach transpiler codepaths to classify files as either CJS or ESM using the same rules as NodeNext