question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support loading ts-morph via esm.sh

See original GitHub issue

Describe the bug

Version: 10.0.2

When loading ts-morph@10.0.2 in the browser via ESM import, it gives an error “require is not defined”, pointing at this.fs = require("fs"). If you pin to ts-morph@10.0.1, it works fine.

To Reproduce

https://codesandbox.io/s/stoic-dewdney-blqc3?file=/index.html

The sandbox shows the error. If you change the 10.0.2 to 10.0.1 inside index.html and reload the output, it works.

Expected behavior

You can load ts-morph in the browser from a ES module CDN.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dsherretcommented, Sep 4, 2021

Oh, wait… I forgot that’s a .ts file and won’t work in the browser. I’ll look into changing the release so this can work.

0reactions
dsherretcommented, Sep 4, 2021

@schickling I believe you should be able to just use the deno.land/x urls instead of using esm.sh. Let me know if it doesn’t work:

https://github.com/dsherret/ts-morph/tree/latest/deno#ts_morph

(You can specify a version on those by adding @x.x.x after ts_morph. Ex. import { Project } from "https://deno.land/x/ts_morph@12.0.0/mod.ts";)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESM.sh
A fast, global content delivery network for NPM packages with ES6 module syntax.
Read more >
ije/esm.sh: A fast, global content delivery network for ... - GitHub
This only works when the NPM module imports CSS files in JS directly. Web Worker. esm.sh supports ?worker mode to load modules as...
Read more >
Bountysource
Support loading ts-morph via esm.sh. ... Help and Information. Frequently Asked Questions · Bugs and Feature Requests · Fees ...
Read more >
Monorepo for Ts-morph and Related Projects - Morioh
import { createWrappedNode, ClassDeclaration, ts } from "ts-morph"; // some code that creates a class declaration using the ts object const classNode: ts....
Read more >
File System - ts-morph
In most scenarios, you won't have to bother with what's outlined here, but it may be useful in some scenarios (for example, using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found