简体   繁体   中英

How to add compiled javascript library to typescript project?

I have an Typescript project (ProjectA) that uses few nodes packages. Aside I have babel project (ProjectB) which build configuration supports output for multiple module definition standards: amd, common.js, esm.

Is it possible to incorporate compiled ProjectB into ProjectA?

So far inside ProjectA i have created folder for ProjectB-dist, and placed there all of the outputs of ProjectB.

Inside one of the .ts files I have tried to import ProjectB as:

import ProjectB form './ProjectB-dist/output.common.js'

I have placed types for this project inside my @types folder. But compiler complains:

Could not find a declaration file for module './ProjectB-dist/output.common.js'.

Maybe I'm missing something with module concept?

If you want to import a library, just use the path to it (without the .js extension): import "./ProjectB-dist/output.common" . If after doing this the compiler still complains about a declaration file, then create that file named output.common.d.ts in a directory and put the following into it: declare module "./ProjectB-dist/output.common";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM