9

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.

2

2 Answers 2

5

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't. The file exists entirely of what was posted above. I tried to make it as bare bones as possible to fix the compiler error.
3

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...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.