I have a really basic Typescript file being imported into a Register.tsx file. I keep getting the following error when building with npm.
test.ts' is not a module
test.ts
export class Tester {
test(): string {
return "test";
}
}
Register.tsx
import { Tester } from "./../test"
I've read several different solutions but I can't see anything I'm doing wrong or different. Am I missing something glaringly obvious? I'm new to Typescript / npm / Webpack.
Does test.ts export anything else or access the module
object? My experience is that TypeScript throws the 'not a module' warning whenever if it sees the NodeJS module
object, which NodeJS uses for exports instead of the TS export
notation.
My team has an environment in which we include plain JavaScript files into certain TypeScript projects, and we get the same 'not a module' warning whenever importing anything with lines like:
module.exports = X
or module.exports.thing = X
(which happens to be all of the plain-Javascript files.)
When this happened to me, restarting my yarn dev did solved the issue. It seems tsc is not restarted completely when watch reload, and that it does not discover new files properly...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With