Open kareem-abdul opened 2 years ago
I can take a look at this soon. Thanks for your patience.
any updates on this @jonkwheeler
We have recently begun migrating our projects over to ESM modules and ran into this issue.
Does https://github.com/jonkwheeler/tsconfig-replace-paths/pull/28 fix this issue?
@sourcecodes2 I'll have to take a peek. Sorry for the delay all. I had a kid born recently and life has gotten a bit chaotic.
There's an easy fix to this though.
"@services": [ "app/service/index.service.js"]
This could easily be @service/index
or @service
and then app/service/index.js
export default index.service.js
. Am I missing something?
Alright, I just did this in one of my repo's and had no issue at all.
The original file has this import
import { typeSystem } from '@typeSystem'
My tsconfig has this
"paths": {
"@typeSystem": ["./src/variables/typeVars/typeSystem.js"]
},
And the CommonJS output was this
var _typeSystem = require("../../variables/typeVars/typeSystem.js");
Everything worked perfectly. Am I missing something? Is there a repo I can have to replicate this?
Alright, I just did this in one of my repo's and had no issue at all.
The original file has this import
import { typeSystem } from '@typeSystem'
My tsconfig has this
"paths": { "@typeSystem": ["./src/variables/typeVars/typeSystem.js"] },
And the CommonJS output was this
var _typeSystem = require("../../variables/typeVars/typeSystem.js");
Everything worked perfectly. Am I missing something? Is there a repo I can have to replicate this?
My mistake, having re-read the original issue @kareem-abdul submitted, it is a slightly different issue to the one I have experienced.
I need to specify the ".js" extension within the imports (import { a } from '@services/foo/bar.service.js'
). I am simply using the tsconfig paths array to alias the directory, as normal ("@services/*": "services/*"
).
The issue I'm specifically experiencing is the ".js" file extension suffix in the import path, which appears to be required when using ES modules. Beforehand with commonjs modules I was omitting the .js extension (import { a } from '@services/foo/bar.service
) but this appears to be no longer possible with the latest version of Typescript and ES modules.
Hi, in a node typescript ESM project, the modules are imported with extensions, ie,
so for such a case, we could provide a path in tsconfig as bellow
But providing such a path in ts-config would break the current setup as there are no js files on the source directory during compilation. Most probably the base-url would be pointing to the ./src folder and there would be no way to point it to the dist folder as doing so would cause eslint or tsc to fail. So is it possible to add support for extensions? or did I miss something?
Attaching my tsconfig.json, package.json, and a verbose output of tsconfig-replace-paths bellow
tsconfig
package.json
build output