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

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

Closed
huan opened this issue Jul 26, 2016 · 3 comments
Closed

Comments

@huan
Copy link

huan commented Jul 26, 2016

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.

@blakeembrey
Copy link
Member

blakeembrey commented Jul 26, 2016

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

@glebmachine
Copy link

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?

@blakeembrey
Copy link
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
Projects
None yet
Development

No branches or pull requests

3 participants