问题
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