#Importing typescript-only packages.
29 messages · Page 1 of 1 (latest)
there is no such thing as typescript-only packages
the errors you are facing is related to ES modules
you can only use an import statement in a file that is an ES module
a file is only an ES module if it has at least one export statement
👉 to solve the problem, just add an export statement to your file, to turn it into an ES module
if you have nothing to export, you can export an empty object like so
export {};
👉 you could also set the option moduleDetection to force to force all files to be considered as ES modules
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
@heavy haven
Just to nitpick, technically there are types only packages
I mean that I want to have private npm package that will only contain ts file, that will be imported just like regular files in typescript project.
The problem is that when this code is in node_modules, it is not treated like regular .ts file
And it seems to be related to the bundling process
So I would like to know if this is somehow doable with tsc alone or other tools
Normally tsc, will generate file with require/import statements so when the output will run it will have problem because node cannot run ts files
So, the general question is can node_module not include build step to js, so that the file gets imported in project just like it was an ordinary file in project.
My package already had exported function
Also I want to say that I would not like to set whole project's where package is imported package.json to include type: "module"
Yeah don't do that
build it to .js with declaration: true and declarationMap: true
I've never seen it done. I guess that TS looks only for .d.ts files in node_modules, but not sure
I think you would have to do a folder with symlinks into the project folder if you wanted that
@heavy haven
I can import ts files and types are correctly discovered, but it its not treated by build tool as something to be transpiled
Oh really?
So your issue is that tsc doesn't compile the .ts files in node_modules? I wouldn't expect it to
Have you specified the folder as included in tsconfig "include" section?
Hmm that would gives problems because you'd get a node_modules folder in dist, or it would complain that its not in dist