Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin breaks with tsmorph. #2

Closed
vedantroy opened this issue May 2, 2021 · 2 comments
Closed

Plugin breaks with tsmorph. #2

vedantroy opened this issue May 2, 2021 · 2 comments

Comments

@vedantroy
Copy link

I am using the Deno version of tsmorph. When I run the build, with the following script:

import * as esbuild from 'https://deno.land/x/esbuild/mod.js'
import { cache } from 'https://deno.land/x/esbuild_plugin_cache@v0.2.6/mod.ts'


const importMap = JSON.parse(Deno.readTextFileSync('./import_map.json'));

await esbuild.build({
    entryPoints: ["src/main.ts"],
    bundle: true,
    format: 'esm',
    outfile: "bundle.js",
    plugins: [cache({importmap: importMap, directory: ".cache"})]
})

esbuild.stop();

and the command deno run --no-check --allow-read --allow-write --allow-env --allow-run --allow-net esbuild.ts where main.ts is a file that imports tsmorph, like so:

import * as tsmorph from "https://deno.land/x/ts_morph@10.0.2/mod.ts";

I get the following errors:

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:17:21: warning: Top-level "this" will be replaced with undefined since this file is an ECMAScript module
        17 │ var __spreadArray = (this && this.__spreadArray) || function (to...
           ╵                      ~~~~
   deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:153191:0: note: This file is considered an ECMAScript module because of the "export" keyword here
    153191 │ export { ts };
           ╵ ~~~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3689:33: error: [plugin: deno-cache] Not Found
    3689 │                     fs = require("fs");
         ╵                                  ~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3421:33: error: [plugin: deno-cache] Not Found
    3421 │ ...         var _a = require("perf_hooks"), nodePerformance_1 = _a...
         ╵                              ~~~~~~~~~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7195:34: error: [plugin: deno-cache] Not Found
    7195 │                 _crypto = require("crypto");
         ╵                                   ~~~~~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7190:32: error: [plugin: deno-cache] Not Found
    7190 │             var _path = require("path");
         ╵                                 ~~~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7302:32: error: [plugin: deno-cache] Not Found
    7302 │                         require("source-map-support").install();
         ╵                                 ~~~~~~~~~~~~~~~~~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7350:40: error: [plugin: deno-cache] Not Found
    7350 │                 var inspector = require("inspector");
         ╵                                         ~~~~~~~~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7191:30: error: [plugin: deno-cache] Not Found
    7191 │             var _os = require("os");
         ╵                               ~~~~

 > deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7203:33: error: [plugin: deno-cache] Not Found
    7203 │             var Buffer = require("buffer").Buffer;
         ╵                                  ~~~~~~~~

�[0m�[1m�[31merror�[0m: Uncaught (in promise) Error: Build failed with 8 errors:
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3421:33: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3689:33: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7190:32: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7191:30: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7195:34: error: [plugin: deno-cache] Not Found
...
    at �[0m�[1m�[3mfailureErrorWithLog�[0m (�[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m1398�[0m:�[0m�[33m15�[0m)
    at �[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m1080�[0m:�[0m�[33m28�[0m
    at �[0m�[1m�[3mrunOnEndCallbacks�[0m (�[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m876�[0m:�[0m�[33m47�[0m)
    at �[0m�[1m�[3mbuildResponseToResult�[0m (�[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m1078�[0m:�[0m�[33m7�[0m)
    at �[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m1185�[0m:�[0m�[33m14�[0m
    at �[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m567�[0m:�[0m�[33m9�[0m
    at �[0m�[1m�[3mhandleIncomingPacket�[0m (�[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m664�[0m:�[0m�[33m9�[0m)
    at �[0m�[1m�[3mreadFromStdout�[0m (�[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m534�[0m:�[0m�[33m7�[0m)
    at �[0m�[36mhttps://deno.land/x/esbuild@v0.11.17/mod.js�[0m:�[0m�[33m1663�[0m:�[0m�[33m11�[0m

here is the un-messed up version:

error: Uncaught (in promise) Error: Build failed with 8 errors:
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3421:33: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3689:33: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7190:32: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7191:30: error: [plugin: deno-cache] Not Found
deno-cache:https://deno.land/x/ts_morph@10.0.2/common/typescript.js:7195:34: error: [plugin: deno-cache] Not Found
...
    at failureErrorWithLog (https://deno.land/x/esbuild@v0.11.17/mod.js:1398:15)
    at https://deno.land/x/esbuild@v0.11.17/mod.js:1080:28
    at runOnEndCallbacks (https://deno.land/x/esbuild@v0.11.17/mod.js:876:47)
    at buildResponseToResult (https://deno.land/x/esbuild@v0.11.17/mod.js:1078:7)
    at https://deno.land/x/esbuild@v0.11.17/mod.js:1185:14
    at https://deno.land/x/esbuild@v0.11.17/mod.js:567:9
    at handleIncomingPacket (https://deno.land/x/esbuild@v0.11.17/mod.js:664:9)
    at readFromStdout (https://deno.land/x/esbuild@v0.11.17/mod.js:534:7)
    at https://deno.land/x/esbuild@v0.11.17/mod.js:1663:11

I'm not sure what is going on here, but I know that tsmorph (compiles) imports correctly when I do deno compile src/main.ts, so I think this is not an issue with tsmorph being Deno incompatible.

@dalcib
Copy link
Owner

dalcib commented May 2, 2021

This is a known issue of Esbuild, not evaluating conditions or try...catch for require().
See evanw/esbuild#1132 and evanw/esbuild#1127.
This problem happens because Esbuild does not evaluate the code in the build time.
Esbuild will walys try to resolve the require, which in these cases don`t exist because they are Node internal modules.

   // https://deno.land/x/ts_morph@10.0.2/common/typescript.js:3417
    function tryGetNodePerformanceHooks() {
        if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof module === "object" && typeof require === "function") {
            try {
                var _a = require("perf_hooks")
                ...
            }
            catch (_b) {
                // ignore errors
            }
        }
    }

@dalcib
Copy link
Owner

dalcib commented May 8, 2021

Closing, since this issue is not related to this project.

@dalcib dalcib closed this as completed May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants