Skip to content
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

tsconfig.json/paths not working with ts-node #138

Closed
unional opened this issue Jun 19, 2016 · 48 comments · Fixed by rootstrap/node-ts-api-base#1
Closed

tsconfig.json/paths not working with ts-node #138

unional opened this issue Jun 19, 2016 · 48 comments · Fixed by rootstrap/node-ts-api-base#1
Labels
external research Needs design work, investigation, or prototyping. Implementation uncertain.

Comments

@unional
Copy link
Contributor

unional commented Jun 19, 2016

One neat trick to use tsconfig.json/paths is to pointing the module name to your source file:

// tsconfig.json of blue-tape-fixture
{
  ...
  "paths": {
    "blue-tape-fixture": [ "src/" ]
  }
}

This way, your test files can reference the source as if it is a proper module:
image
You can see it is working in vscode. But it does not when I run test with ts-node:

// package.json
{
  "scripts": {
    "test": "ts-node -P tsconfig.build.json node_modules/blue-tape/bin/blue-tape \"test/**/*.ts\" | tap-spec"
  }
}

The error is:

Error: Cannot find module 'blue-tape-fixture'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)

You can see it here: https://github.com/unional/blue-tape-fixture/tree/ts-node

# clone
npm install
npm test
@blakeembrey
Copy link
Member

@unional That's the node.js error - TypeScript is working fine, but node will never be able to resolve an alias like that unless TypeScript emits code that rewrites paths. What do you think is the solution here?

@unional
Copy link
Contributor Author

unional commented Jun 19, 2016

I see. In order for it to work, a module-path-rewriter need to be written and loaded by ts-node.
Alternatively is to load the transpiled code dist/*, which kind of defeat the purpose of ts-node (I said kind of because the test files, in this use case, can remain as ts files).

@blakeembrey
Copy link
Member

This module uses the emitted code though - it's TypeScript itself that doesn't do any rewriting right?

@unional
Copy link
Contributor Author

unional commented Jun 20, 2016

Just check. Nope it does not do any rewriting. Seems like the baseUrl and paths is only used during compilation. By design or bug on TS side?

@unional
Copy link
Contributor Author

unional commented Jun 20, 2016

Updated https://github.com/unional/blue-tape-fixture/tree/ts-node to demo the issue.
run npm run build-test and see under dist/test/index.ts. It is still requiring blue-tape-fixture

@unional
Copy link
Contributor Author

unional commented Jun 20, 2016

Confirm above statement: microsoft/TypeScript#5039 (comment)

@blakeembrey
Copy link
Member

@unional Yeah, it's tricky. I can understand TypeScript's stance, if they don't have a solution for it built-in I think we can investigate adding a plugin once they implement the pluggable transforms in TypeScript 2.0. This is definitely more of a user-land feature.

@blakeembrey blakeembrey added the research Needs design work, investigation, or prototyping. Implementation uncertain. label Jul 23, 2016
@sanex3339
Copy link

any news? i want to use 'paths' option in my tests

@blakeembrey
Copy link
Member

blakeembrey commented Oct 2, 2016

No, it does not work and is not expected to work. Someone can still implement a plugin (which would be very valuable to others too!), but I am not currently working on it.

@jonaskello
Copy link
Contributor

jonaskello commented Dec 26, 2016

Maybe this could be solved by augmenting node's loading rather than having typescript re-write the paths. There are some alternatives mentioned here. In particular I'm thinking that wrapping the global require and just changing the path according to tsconfig would be the simplest solution.

@jonaskello
Copy link
Contributor

When I looked closer I realised that wrapping global require is not possible in a way that replaces it (the example above installs a separate require function). However it is possible to patch Module._load like is done in mock-require. I did some experiments with this and it seems doable. I'll try to put together a PR to demonstrate.

@jonaskello
Copy link
Contributor

For those interested I did a PR to enable execution of projects with tsconfig paths in #254.

@jonaskello
Copy link
Contributor

Instead of the PR, I have now created the tsconfig-paths package that makes it possible to automatically resolve paths during execution with ts-node, node, or mocha. Just follow the instructions in the readme.

@shirakaba
Copy link

shirakaba commented Apr 24, 2017

Note to all using @jonaskello 's tsconfig-paths:

The errror "Missing paths in compilerOptions. tsconfig-paths will be skipped" means that you don't have any paths property specified in your tsconfig.json. I had been able to use imports relative to my src directory just by specifying "baseUrl": ".", but to get ts-node/node/mocha to understand the same imports, I also needed to specify a paths property in my tsconfig.json, eg:

"paths": {
  "src/*" : ["./src/*"]
}

Hope this helps another overwhelmed soul.

@michaeljota
Copy link

@shirakaba Just a note, you can set your "baseUrl" to "./src/" and "paths" like this

"paths": {
  "*" : ["./*"]
}

I will be the same, but you are able to add more paths with the same root more easily.

@ashok-sc
Copy link

ashok-sc commented Dec 5, 2017

I've tried nearly all the above solutions and I'm still getting Module not found: Error: Can't resolve ....

What's the solution here? I have updated my tsconfig.json webpack.config.js and even tried tsconfig-paths. None of these work.

//tsconfig.json
{
  ...
  "baseUrl": "./src",
    "paths": {
      "@src/*": [
        "*"
      ]
    }
}

@jonaskello
Copy link
Contributor

jonaskello commented Dec 5, 2017

@ashok-sc ts-node has no support for paths in tsconfig.json, and no plans to add it. I think your best bet to get it working is using tsconfig-paths. If you have trouble using it feel free to file an issue at that repo.

If you are using webpack the scenario is quite different. If you are using ts-loader you might want to try tsconfig-paths-webpack-plugin altough it is still early in development. If you are using awesome typescript loader then it has this type of plug-in built-in.

@michaeljota
Copy link

@ashok-sc As @jonaskello said, there is no plan to support path, as you need to replace the path call with the proper full path in order to be understandable for Webpack. You could use Awesome Typescript Loader that have a plugin out-the-box for that, but still, it needs to be a plugin.

@ashok-sc
Copy link

ashok-sc commented Dec 5, 2017

Hey @jonaskello and @michaeljota thanks for the help! I am in fact using awesome-typescript-loader with webpack. However, the instructions are quite poor. I understand that you may not have the answers here, but I thought I'd give it a shot anyway.

The instructions state to add the TsConfigPathsPlugin, but it's not clear as to what it needs in the constructor. Here's what I tried:

new TsConfigPathsPlugin({
    configFileName: path.join(__dirname, './tsconfig.json'),
    compiler: 'typescript'
  })

This doesn't seem to work though and I still get module not found.

Anyway, if you don't have the answer of the top of your head feel free to ignore.

@jonaskello
Copy link
Contributor

Here's a gist of what a webpack config should look like with awesome-typescript-loader's tsconfig paths plugin. I don't pass anything in the constructor in my config, but maybe you need it if your tsconfig.json is in a non-standard location.

var TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;

module.exports = {
	entry: ...,
	output: ...,
	resolve: {
		extensions: ['...'],
		plugins: [
			new TsConfigPathsPlugin()
		]
	}
}

@jonaskello
Copy link
Contributor

@ashok-sc If it does not work, you can try version 0.2.0 of tsconfig-paths-webpack-plugin. I have added code that prints the path that it tries to load the tsconfig.json from.

Note, tsconfig-paths-webpack-plugin is used instead of the one in awesome-typscript-loader. You can also use it with ts-loader.

yeldiRium added a commit to thenativeweb/wolkenkit that referenced this issue Aug 5, 2019
Ts-node does not load the paths from tsconfig.json by itself. Thus in
the tests run with ts-node the custom types for external packages (and
things like our offspring) can't be resolved.
The package tsconfig-paths has resulted from a discussion about this
topic on
github (TypeStrong/ts-node#138 (comment)),
which loads said modules.
@viT-1
Copy link

viT-1 commented Aug 8, 2019

@alexeychikk

  1. module-alias not the best way if you use es6
    Not working with native ES modules ilearnio/module-alias#59
  2. If project doesn't use webpack "even webpack" is not usecase.
  3. May be you can help me to configure tsconfig-paths to use it as npm script with ts-node for script.ts and extended tsconfig containing outDir?
    Bug with extends property in tsconfig dividab/tsconfig-paths#39

goloroden added a commit to thenativeweb/wolkenkit that referenced this issue Oct 15, 2019
…#183)

* WIP

* WIP

* WIP

* Clean up dependencies.

* Add worker messaging.

* Add CircleCI configuration.

* Fix CircleCI configuration.

* Add CircleCI badge.

* Update base image.

* Rename v2 to V2.

* Make integration tests run.

* WIP

* Cache messages before the first worker has registered.

* WIP: Introduce filestore api.

* Remove unneeded tests.

* Add documentation.

* Rename storage to stores.

* Work on base structure. (#157)

* WIP

* Immutable Commands and Events. Streamline eventstores api.

* WIP

* Seperate commands and events into internal and external. Streamline elements wording.

* Introduce dispatcher server.

* Fix duplicate IP addresses (happens on CircleCI). Add Dependabot.

* Fix branch.

* Change retry options for tests.

* Switch CircleCI configuration from Docker to VM.

* Try to fix CircleCI configuration.

* Try to fix CircleCI configuration.

* Try to fix CircleCI configuration.

* Fix IP address test.

* Implement event server.

* Wait for connection.

* Add missing contributors (transfer from other repositories).

* Update Dockerfiles. Introduce Consul.

* Further clean up.

* Update lock file.

* Update .dockerignore file.

* Implement in-memory lockstore and first draft of commandstore. Remove RabbitMQ support.

* Add isLocked function. Update dependencies.

* Increase test timeout.

* Remove command store.

* Lockstore implementations (#160)

* Add sortObjectKeys with recursive option.

* Ensure object key order when getting lock name

* Add unit and integration tests for Postgres Lockstore

* Add Postgres implementation for lockstore

* Add MySQL/MariaDB Lockstore

* Select only expiresAt to check when lock exists

* Add SqlServer lockstore implementation

* Code cleanup in Postgres Lockstore

* Add MongoDb lockstore implementation

* Add Redis container + client

* Add Redis lockstore implementation

* Ensure nested keys are also sorted.

* Fix test names for sortObjectKeys

* Stick to redis client 2.8.0

* Await release lock on failure for InMemory Lockstore

* Fix remarks on MariaDB Lockstore.

* Fix remarks on MySQL Lockstore.

* Use object parameter on sortObjectKeys

* Update InMemory Lockstore for sortObjectKeys

* Update MariaDb Lockstore for sortObjectKeys.

* Fix remarks on MongoDb Lockstore.

* Update MySql Lockstore for sortObjectKeys +  inline releaseLock

* Fix remarks on Postgres Lockstore.

* Fix remarks on Redis Lockstore.

* Fix remarks on SqlServer Lockstore.

* Add maxLockSize on lockstore implementations + tests.

* Inject Lockstore into Commandstore.

* Add semi-columns on MySql/MariaDb lockstores.

* Reuse createPool for SqlServer

* Remove Lockstore injection in CommandStore

* Add nonce and optional maxLockSize on Redis Lockstore.

Redis username is now optional.

* Add nonce and optional maxLockSize on Postgres Lockstore.

* Update Redis test config.

* Set nonce default to null string for Redis.

* Add nonce and optional maxLockSize on SqlServer Lockstore.

* Add nonce and optional maxLockSize on MongoDb Lockstore.

* Add nonce and optional maxLockSize on MySql Lockstore.

* Throw error on release only if lock is still active.

* Select expiresAt for check on release

* Add nonce and optional maxLockSize on MariaDb Lockstore.

* Readjusted delays for renew lock test. SqlServer tends to be flaky.

* Add tests for strict lock mode with nonce on renew and release.

* Remove useless parameter initialization.

* Implement the in-memory queuestore. (#162)

* Add draft for in-memory queue store.

* Fix casing.

* Experimentally switch to TypeScript.

* Fix whitespace.

* Introduce types folder.

* Introduce src folder.

* Switch to Node.js 12. Review a few files.

* Introduce Dictionary and offspring. Migrate defekt.

* Refactor elements and start to work on application loading.

* WIP

* Finalize Application and clean up.

* Turn Dictionary type to IDictionary interface.

* Remove leading I from interfaces. Remove types folders.

* Clean up logger service and client service.

* WIP

* Add types to omitByDeep.

* Add aggregateIdentifier to Snapshot and check for it in Aggregate.

* Add InvalidOperation error.

* Add EventStore interface.

* Migrate InMemoryEventStore to TypeScript.

* Rename EventStore to Eventstore

* WIP

* Finish repository.

* Implement read aggregate service.

* Introduce aggregate service.

* Revert queue store to JavaScript.

* Add typings for assertthat.

* Make unit tests run for utils.

* Improve ts-test script to exclude shared folder.

* Add missing types for module uuidv4.

* Export and import Todo type correctly.

* Add package tsconfig-paths and integrate it into ts-test script

Ts-node does not load the paths from tsconfig.json by itself. Thus in
the tests run with ts-node the custom types for external packages (and
things like our offspring) can't be resolved.
The package tsconfig-paths has resulted from a discussion about this
topic on
github (TypeStrong/ts-node#138 (comment)),
which loads said modules.

* Fix broken import in Application.ts.

* Migrate CommandExternalTests.

Currently only half of them runs, because Application.load fails.

* Rename ICustomError from defekt to CustomError.

* Change excluded files in mocha call.

The previous value was left over from a test <.<

* Let mocha run all tests instead of stopping on first failing test.

* Return transformed configuration in getApplicationConfiguration.

It returned an empty object before that was just not filled with values.

* Remove Is from interface names and validate correct folder.

* Migrate part of the ApplicationTest to TypeScript.

* Add types for package isolated.

* Install @types/shelljs.

* Move @types/shelljs to devDependencies.

* Fix assertthat types: atLeast/atMost can support more than numbers.

* Change tsconfig root directory so that it includes the tests.

* Fix Application: build external objects from internal ones.

Instead of from the not yet existing external ones.

* Fix Application: internal and documentation.

Flatten structure of internal objects; Don't give documentation a default value.

* Adjust tsconfig.json to accept tests outside src.

* Apply new types in assertthat also to not property.

* Add type signatures to tests suites.

* Remove project config from tsconfig.json.

* Migrate ApplicationTests and CommandExternalTests to TypeScript.

* Move InMemoryEventStore to separate file; Re-export from index.ts.

* Migrate CommandInternalTests to TypeScript.

* Remove package get-option-tests.

* Migrate EventExternalTests to TypeScript.

* Migrate EventInternalTests to TypeScript.

* Migrate LoggerServiceTests to TypeScript.

* Migrate ClientServiceTest to TypeScript.

* Replace AppServiceTest with AggregateServiceTest in TypeScript.

* Add test for AggregateApiForReadOnly.

* Fix file name, and introduce a new suite.

* Add tests for AggregateApiForEvents.

* Add more tests.

* Test correct call to event handle function using sinon fake.

* Fix version constraint for sinon.

* Reorder InMemoryEventstore functions to match interface.

* Write test for Aggregate and remove old js tests.

* Migrate sendCommand and its test to TypeScript.

* Fix some filenames and only run tests matching *Tests.ts.

* Remove unit tests for stores; TypeScript makes them unnecessary.

We only need the integration tests in the future.

* Replace eslint rule no-useless-constructor with TS equivalent.

* Migrate Command Http endpoint to TypeScript.

- add type declarations for limes
- extend express' `Request` with fields from limes validation
  middleware
- adjust some types in various places to work with express and limes
  types
- add new error for failing authentication

* Add type definitions for partof.

* Add test-debug script and add --exit flag to mocha calls.

This is to end the runner after all tests have completed, even if
there are still streams/sockets/stuff like that open.
We can't prevent this, since supertest and express can't explicitly
end connections.

* Migrate event http api to TypeScript.

* Migrate health http api to TypeScript.

* Migrate static http endpoint to TypeScript.

* Add type definitions for streamtoarray.

* Migrate Repository tests to TypeScript.

* Update dependencies.

* Add type definition for marble-run.

* Remove unit tests for cores since they contain only option tests.

* Migrate InMemoryDispatcher to TypeScript.

* Add types for buntstift.

* Migrate docker related scripts to TypeScript.

* Update eslint-config-es to newest version and simplify eslintrc.

* Update eslint-config-es to 3.1.4.

* Fix dependabot configuration.

* Install roboter v7.1.0 and assertthat v4.0.1

* Upgrade dependencies.

* Pin dependency versions.

* Replace offspring defekt with defekt v3.0.0.

* Move type declaration dependencies to devDependencies.

* Replace nodeenv and uuidv4 type declarations with package updates.

* Replace processenv type declarations with package update.

* Replace isolated type declarations with package update.

* Replace record-stdstreams type declarations with updated package.

* Revert integration pre/post to before mistake.

* Replace buntstift, limes, validate-value type declarations.

* Replace streamtoarray by TypeScript migrated version.

* Replace partof with TypeScript version.

* Replace flaschenpost type declarations with new version.

* Remove marble-run type declarations.

* Update dependencies.

* Clean up TypeScript code style and adhere to new eslint rules.

* Make tests run with roboter.

* Store rootDirectory in application.

* Pass absolute path when calling getLoggerService.

* Fix require of assertthat in javascript tests.

* squash with logger fix

* Supress log output in tests.

* Add filestore interface; Migrate filesystem-filestore.

* Add missing method `authorize` to Filestore interface.

* Migrate file API to TypeScript.

* Fix ESLint errors.

* Add source paths of debug messages to tests again.

* Remove obsolete npm scripts for test and build.

* Replace pump with stream.pipeline.

Closes #170.

* Move S3 filestore to TypeScript.

* Migrate more files to TypeScript.

* Update dependencies and fix eslint problems.

* Rename static async `initialize` "constructors" to `create`.

* Fix linting issue in FileSystemFilestore.

* Remove unneeded packages.

* Migrate MariaDbEventstore to TypeScript; Replace mysql2 with mysql.

* Migrate the MySqlEventstore and fix some issues with the initialize/create change.

* Move promisified mysql query logic into separate file.

* Migrate MariaDbLockstore to TypeScript.

* Migrate MySqlLockstore to TypeScript.

* Replace limit-alphanumeric by own implementation.

* Add @types/mysql

* Migrate MongoDB eventstore to TypeScript.

* Migrate PostgreSQL eventstore to TypeScript.

* Migrate SQL Server eventstore to TypeScript.

* Update dependencies.

* Start to migrate the microservices.

* Remove setting the log level on CircleCI, as this is now done using a .env file.

* Migrate PostgreSQL lockstore to TypeScript.

* Extract maxDate to its own file.

* Improve comments.

* Use the correct exception type for invalid operations.

* Fix naming, simplify code.

* Use limitAlphanumeric; Set onUnexpectedClose methods to protected.

* Fix aggregateIdentifier usage in mysql queries.

* Migrate Eventstore integration tests to TypeScript.

* Fix left over bugs in the migrated Eventstores.

* Migrate integration tests for Filestores and fix some bugs.

* Migrate Lockstores and tests to TypeScript.

* Replace sort-keys with self implemented version.

The self-implemented version used befor the typescript migration
passed non-objects through instead of throwing an exception, as
sort-keys does. We needed the old behavior back.

* Fix issues arising from merge.

* Migrate MongoDB and Redis lockstores to TypeScript.

* Rename factory functions to createXyz.

* Fix import path.

* Update Node.js base image.

* Add tests for sortKeys.

* Add types for freeport-promise.

* Update measure-time and runfork.

* Make tests run.

* Update CircleCI and Dependabot configuration.

* Optimize bug template.

* Remove dependency on freeport-promise.

* Add badges, and move license to external file.

* Remove unneeded dependencies.

* Increase test timeout.

* Finally remove keys and remove Consul configuration.

* Enable new topology layer for MongoDB.
@SephReed
Copy link

SephReed commented Dec 4, 2019

@jonaskello You saved my ass here!

Is there any reason why this shouldn't become a default built in part of ts-node? It seems like it would make more sense to include this by default, than to not.

@bennycode
Copy link

Thanks @jonaskello!

It also seems to work when using ts-node through nyc:

nyc.config.js

module.exports = {
  all: false,
  exclude: ['**/*.d.ts', '**/*.test*.ts', '**/index.ts'],
  extension: ['.ts'],
  include: ['src/**/*.ts'],
  reporter: ['text-summary'],
  require: ['tsconfig-paths/register', 'ts-node/register'],
};

mattwynne added a commit to SmartBear/git-en-boite that referenced this issue Aug 4, 2020
See TypeStrong/ts-node#138

This allows us to use custom type declarations and have the compilers
work consistently between tsc, ts-node, mocha and cucumber

It does mean we'll need to remember to add the require for
tsconfig-paths in a couple of other places, probably, like where we use
mocha.

Closes #151
@talwrii
Copy link

talwrii commented Aug 13, 2020

Thank you to janaskello for tsconfig-paths a slight annoyance I have is that it seems like tsconfig-paths needs to be installed in projects themselves for ts-node -r tsconfig-paths/register to work - which is a bit of a pain for third party libraries (my use case of understanding someone else code is perhaps unusual).

I'd also like to say that on newer versions of node you get a MODULE_NOT_FOUND error (other page about this suggest deleting and reinstalling things for this). It's odd how ts-node in one says can "find" the library (because if a file does not exist you get a different error) but then fails to import.

I would vote for ts-node refusing to run if paths is set given that this error is a little cryptic (I didn't find this page until I guessed that the problem might be because ts-node is ignoring paths and googled this - working in someone elses repo).

@blephy
Copy link

blephy commented Oct 2, 2020

I was running on the same issue when running webpack with ts-node (i'm using Typescript language webpack configuration) but already followed the webpack documentation and installed tsconfig-paths.

Just putting "moduleResolution": "node" into my tsconfig.webpack.json resolved the issue.

Hope this help

@SephReed
Copy link

@jonaskello You saved my ass here!

Is there any reason why this shouldn't become a default built in part of ts-node? It seems like it would make more sense to include this by default, than to not.

Apparently I've been through this before... lol.

This really probably should become default behavior.

@rachaeldawn
Copy link

Okay, so I found a solution that works reasonably well for my use-case. I needed this just for Knex's knexfile.ts and couldn't find a solution

Constraints:

  • Every "path" in paths I have has only 1 item in the array
  • I am able to use module-alias as a dev dependency
  • I have only 1 file that requires this fix, however putting this in a fix-paths.ts file works if it is is imported first
  • I am able to use "resolveJsonModule": true

Code

import moduleAlias from 'module-alias';
import * as path from 'path';
import { compilerOptions } from './tsconfig.json';

const root = path.join(__dirname, compilerOptions.baseUrl || '');

for (const [key, paths] of Object.entries(compilerOptions.paths)) {
  const target = path.join(root, paths[0]);
  moduleAlias.addAlias(key, target);
}

@SephReed
Copy link

SephReed commented Jul 27, 2021

Clearly I'm a weirdo. This is my fourth time finding this thread, but it doesn't appear to get much activity. It's probably because I use mono-repos.

For future me coming back here, this is the link: https://www.npmjs.com/package/tsconfig-paths

@fatihaziz
Copy link

fatihaziz commented Sep 24, 2021

maybe my workaround will help:

  1. install required plugins:
    npm i -D ttypescript typescript-transform-paths ts-node tsconfig-paths.
    these are packages that will help us to transform the paths.

  2. then, on tsconfig.json, i put:

    {
     "ts-node": {
       "transpileOnly": true,
       "require": [  // set this so you dont need to use ts-node -r 
     	"typescript-transform-paths/register",
     	"tsconfig-paths/register"
        ]
     },         
     "compilerOptions": {
        "composite": true,
        "rootDir": ".", // must define
        "baseUrl": "src", // must define, the paths will relative to this
        "outDir": "lib", 
        "skipLibCheck": false,
        "paths": {
     	"@app/*": ["./*"],
     	"@controllers/*": ["./controllers/*"],
        },
         "plugins": [
     	  { "transform": "typescript-transform-paths" }
         ]
     }
    }
    
  3. then we can use this on our codes everywhere:

    import myControllers from "@controllers/main.ts"
    
  4. then to compile, we need to run npx ttsc -p tsconfig.json , we use npx so we dont need to install ttypescript globally

  5. and to run on ts-node, we can simply run npx ts-node -p tsconfig.json src/app.ts, also npx for ts-node.

My conclusion:
To workaround with ts-node paths, we need tsconfig-paths required on ts-node runtime.
but on production we just need to compile them into absolute path, so we use ttypescript and typescript-transform-paths to compile and transform the module paths to absolute path.
then the program can work fine with node without registering tsconfig-paths or any plugins
like node lib/index.js

I hope this solution will help,
also sorry if my word kinda messed up, i try to explain it as simple as possible.

@puchm
Copy link

puchm commented Nov 1, 2021

Does anyone have an idea on how to work around this issue when using ESM? I am normally using node --loader ts-node/esm <path> to start scripts but I could not get it to work using any of the solutions proposed here.

@danielo515
Copy link

@fatihaziz you answer saved my life, thanks!

@droplessdeclan
Copy link

@puchm Did you ever manage to find a solution to this? I'm having the same issue

@cspotcode
Copy link
Collaborator

For a solution you can use today, see #1450

Path mapping is being added as a built-in feature of ts-node in an upcoming release. To follow progress, see #1585

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external research Needs design work, investigation, or prototyping. Implementation uncertain.
Projects
None yet
Development

Successfully merging a pull request may close this issue.