I have 2 github repositories written in typescript
one for initial data , next one project
what is the correct way to export and import it
here is code from initials repository
import { listInitials} from "./src/list";
import { settingsInitials} from "./src/settings";
import { IInitials } from "./src/types";
const initials : IInitials= {
listInitials,
settingsInitials
}
export default initials
Their types
export interface IListInitials extends Object {
[key: string]: any;
}
export interface ISettingsInitials extends Object {
[key: string]: any;
}
export interface IInitials{
listInitials: IListInitials ,
settingsInitials: ISettingsInitials
}
package.json from main repositroy
"dependencies": {
"initials": "git+https://github.com/username/initials.git",
}
index.ts file where I try to import it
import * as Initials from "initials";
console.log(Initials);
Error in console
./node_modules/initials/index.ts 6:15
Module parse failed: Unexpected token (6:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
|
> const initials : IInitials= {
| listInitials,
| settingsInitials
2
Answers
Looks like you are try to run .ts files via node.js
Try to run
Your React projects expects your
initials
module to be built (i.e. to provide JS files)So you either need to run
tsc
on it to build it, and add js artifacts into git (the way it’s done in NPM bundles which provide only js and d.ts),or configure your React compiler to eat ts files in node_modules