While using the new TypeScript feature, so called ES Dynamic Imports, I am not able to run the code of my isomorphic app on the server side using ts-node
.
It seems like the error does not occur when using the webpack module loader which transpiles the code in it's own way and running resulting files in a browser.
The error which I've got:
case 0: return [4 /*yield*/, import("./component/main")];
^^^^^^
SyntaxError: Unexpected token import
Usually TypeScript transpiles the import
expression to something like that: Promise.resolve(require("./component/main"))
, but I can't see it there.
How to fix that? Does it have something common with ts-node
? Or there is a "polyfill" for node.js
?
My tsconfig.json
file:
{
"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;