Skip to content

--require flag does not load from node_modules #257

Description

@jonaskello

As added in #181 ts-node accepts a --require flag. When trying to use this with the tsconfig-paths package it fails to locate the package. Example:

$ ts-node -r tsconfig-paths main.ts 
Error: Cannot find module 'tsconfig-paths'

The reason seems to be this line which does Module._load(id) in order to require the modules specified by --require. If it is changed to require(id)it will locate the package. It seems like Module._load(id) skips loading from node_modules.

The mocha package also has a -r option and looking here it seems they use require to load the modules rather than Module._load. So this example works:

$ mocha --compilers ts:ts-node/register -r node-tsconfig-paths mocha-example.ts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions