If a module exported as node.js export module can we import it using systemjs import method

落爺英雄遲暮 提交于 2019-12-11 23:18:15

问题


In node project we import a module using require keyword, can we import same module using import {} from '' in angular2 project, provided that d.ts is not avaliable? For example can I use this library in my angular2 project

https://github.com/basarat/typescript-collections/issues/new


回答1:


Yes, you can. But you have to use only the ES6 syntax import/export.

For Node.js, you can compile the code using modules format CommonJS or UMD.

Here is a tutorial on how to use TypeScript with SystemJS. SystemJS will load the TypeScript source code and not the compiled code. In order to use JavaScript modules that are installed by npm, use the option packageConfigPaths:

packageConfigPaths: ['node_modules/*/package.json']

See also this thread on GitHub for other options of the SystemJS configuration.



来源:https://stackoverflow.com/questions/37989847/if-a-module-exported-as-node-js-export-module-can-we-import-it-using-systemjs-im

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