Closed yunabe closed 4 years ago
How to reproduce
Run
import {join} from "path";
The, run
join("a", "b");
Expected
path.join("a", "b") is executed.
path.join("a", "b")
Actual An error like "Cannot read property 'join' of undefined"
Reasons
The first cell is converted into JS code like
const path_1 = require("path");, exports.join = path_1.join;
and the second cell is converted into JS like:
path_1.join("a", "b");
But when the second converted cell is executed, path_1 is undefined because these two cells are executed as isolated modules.
Proposals
I think there are two solutions.
.ts
vm
I decided to go with (2) becuase ES module support of vm module is still under experimental as of Sep, 2019.
How to reproduce
Run
The, run
Expected
path.join("a", "b")
is executed.Actual An error like "Cannot read property 'join' of undefined"
Reasons
The first cell is converted into JS code like
and the second cell is converted into JS like:
But when the second converted cell is executed, path_1 is undefined because these two cells are executed as isolated modules.
Proposals
I think there are two solutions.
.ts
file into ES2015 module JS. Then, execute it with Nodevm
module..ts
file into ES2015 module JS. Types are checked in this phase. Then, convert the ES2015 module JS file into CommonJS module.I decided to go with (2) becuase ES module support of
vm
module is still under experimental as of Sep, 2019.