Skip to content

ts-node cannot import pure typescript npm module inside node_modules directory #158

Closed

Description

@huan

I had wroten a pure typescript npm module(without any .js file), and want to use it in my server project which use ts-node(without any compile work like tsc) to run directly. because my case is a server environment, so startup time is not a problem.

the problem is: ts-node cannot use import to load pure typescript inside node_modules directory, I had to do a little hack(move it out, use soft link to link it back).

Which cannot run:

$ npm install
$ ts-node bin/index.ts

/Users/zixia/git/wechaty.io/node_modules/wechaty-io/index.ts:1
(function (exports, require, module, __filename, __dirname) { export * from './src/io-server'
                                                              ^^^^^^
SyntaxError: Unexpected token export

Which could run

my hack is: move wechaty-io module directory out of node_modules, then use soft link to link it back

$ npm install
$ mv node_modules/wechaty-io .
$ ln -s ../wechaty-io node_modules/
$ ts-node bin/index.ts

info io-server Listening on 8080
info io-server init succeed

It seems the import in ts-node will not work when the pure typescript module is in node_modules directory. But, after we changed the physics directory out of node_modules directory, ts-node will make import work properly.

Is there any better solution to do this? Thanks.

Activity

  1. blakeembrey commented on Jul 26, 2016

    @blakeembrey
    Member

    Isn't this a duplicate of #155? We don't enable TypeScript modules in node_modules, node modules should be JavaScript.

  2. glebmachine commented on Jun 19, 2017

    @glebmachine

    Isn't this a duplicate of #155? We don't enable TypeScript modules in node_modules, node modules should be JavaScript.

    That's look weird, because we have got a lot libraries which doesn't compiled properly..

    Is there any option to replace import folder for node_modules? Or disable node_modules ignoring?

  3. blakeembrey commented on Jun 21, 2017

    @blakeembrey
    Member

    @glebmachine Sure. Check the README or the linked issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions