Closed bjornharrtell closed 3 years ago
does this thread help? https://github.com/microsoft/TypeScript/issues/33079
There is a note about it in the Typescript docs:
Note: node module resolution is the most-commonly used in the TypeScript community and is recommended for most projects. If you are having resolution problems with imports and exports in TypeScript, try setting moduleResolution: "node" to see if it fixes the issue.
Taken from here
That's unfortunately what I have already.
But reading a bit more on https://github.com/microsoft/TypeScript/issues/33079 it seems it might need something in an upcoming relase. If you want to be more compatible with what is out now, I think it would work if there was a cjs exports alternative in the package, I got a few of those kind of dependencies already.
as a general rule, all my projects have support for require
and CommonJS but unfortunately I had to drop CommonJS support in local-web-server v5.0.0 due to rollup (used to create the CJS build) not having support for dynamic imports (required to load middleware plugins).
I will look into the Typscript issue.. if it's not too inconvenient, you could use v4.2 until the Typescript people release a fix..
No problem, I'll close this for now.
I got it to work with the latest local-web-server using typescript 4.5 beta.
With this code: (index.ts)
import LocalWebServer from 'local-web-server'
const lws = new LocalWebServer()
and this config: (tsconfig.json)
{
"compilerOptions": {
"module": "node12",
}
}
Running tsc
produced this output: (index.js)
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const local_web_server_1 = __importDefault(require("local-web-server"));
const lws = new local_web_server_1.default();
Results in:
error TS2307: Cannot find module 'local-web-server' or its corresponding type declarations.
5 import LocalWebServer from 'local-web-server';