When using the new TypeScript function, the so-called ES Dynamic Imports , I cannot run the code of my isomorphic application on the server side using ts-node.
It seems that the error does not occur when using the webpack module loader, which translates the code in its own way and runs the resulting files in the browser.
The error I have is:
case 0: return [4 , import("./component/main")];
^^^^^^
SyntaxError: Unexpected token import
Typically, TypeScript converts the expression importto something similar: Promise.resolve(require("./component/main"))but I don't see it there.
How to fix it? Does it have anything to do with ts-node? Or is there a "polyfill" for node.js?
My tsconfig.jsonfile:
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"allowJs": false,
"experimentalDecorators": true,
"importHelpers": true,
"inlineSourceMap": false,
"inlineSources": false,
"lib": [
"DOM",
"ES5",
"ES6",
"ES7"
],
"listFiles": false,
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"preserveConstEnums": false,
"pretty": false,
"removeComments": false,
"strict": true,
"target": "es5"
}
}
the code:
import * as m from "mithril";
import LayoutComponent from "./component/layout";
const render = (
layout: m.ComponentTypes<any, any>,
) => ({ tag, attrs }: m.Vnode<any, any>) => m(layout, attrs, m(tag as any, attrs));
export default {
"/:path...": {
onmatch: async (args, path) => (await import("./component/main")).default,
render: render(LayoutComponent),
},
} as m.RouteDefs;