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.

TypeError: __require.resolve is not a function

See original GitHub issue

Hello! I have an issue with the tsup, I have a TypeScript project with require.resolve function, with pure tsc it works, but when I try to build with tsup-node I get this error:

TypeError: __require.resolve is not a function

I made a reproduction repo for this issue: https://github.com/mvrlin/tsup-require-resolve

I came across this “solution”:

// Before
var __require = (x) => {
  if (typeof require !== "undefined")
    return require(x);
  throw new Error('Dynamic require of "' + x + '" is not supported');
};

// After
var __require = (x) => {
  throw new Error('Dynamic require of "' + x + '" is not supported');
}

if (typeof require !== "undefined") {
  __require = require
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hyriouscommented, Sep 10, 2021

Since esbuild 0.12.26, this issue should be solved automatically by updating dependencies. (npm update) @mvrlin Can you confirm that?

1reaction
hyriouscommented, Sep 8, 2021

@screetBloom Yes that should work, but it will lose code splitting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: require.resolve is not a function · Issue #213 - GitHub
A workaround for this is to use node's require via global.require . It looks like a module you're using is using it, this...
Read more >
node.js - require.resolve() works. Why doesn't module.parent ...
TypeError : module.parent.require.resolve is not a function. Oddly though, console.log module.parent.require.toString() returns .
Read more >
TypeError: require(...) is not a function in Node.js | bobbyhadz
To solve the "TypeError: require(...) is not a function", make sure to place a semicolon between your require call and an immediately invoked...
Read more >
Node.js v19.3.0 Documentation
If the function does not return a promise, assert.rejects() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error ......
Read more >
How to solve the "is not a function" error in JavaScript
js we use require() to load external modules and files. This can cause, in some cases, an error like this: TypeError: require(...) is...
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