Typescript import ts file from node module

允我心安 提交于 2019-12-13 02:02:25

问题


Maybe it's a duplicate but I've searched for an hour and haven't found the answer.

I have a node module named a-module which contains some .ts files (for example a.ts)

I have another node module b-module which has a-module among its dependencies.

I want to import some .ts file from a-module to b-module. In some file within b-module I write:

import a = require('a-module/a');
console.log(a);

When then I'm trying to compile b-module with tsc, is says

Cannot find external module 'a-module/a'.

What am I doing wrong?

P.S. I have ArcticTypescript plugin for SublimeText, and seems that it is enough intelligent to find a-module/a. Why then tsc doesn't manage to locate my file?

P.P.S My file structure looks like that

b-module/
  node_modules/
    a-module/
      a.ts
  b.ts

I'm trying to import a.ts to b.ts.


回答1:


import a = require('a-module/a');

You need to either use relative paths i.e. ../a-module/a or declare it for TypeScript explicitly i.e. declare module "a-module/a".



来源:https://stackoverflow.com/questions/30525625/typescript-import-ts-file-from-node-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!