Skip to content

Commit

Permalink
catch pkg undefined error when using realImport and use realRequire i…
Browse files Browse the repository at this point in the history
…nstead
  • Loading branch information
burgerni10 committed Aug 3, 2022
1 parent 60cc86d commit 5072d18
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/transport-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ async function loadTransportStreamBuilder (target) {
}
// TODO: Support ES imports once tsc, tap & ts-node provide better compatibility guarantees.
fn = realRequire(decodeURIComponent(target))
} else if (toLoad.endsWith('.js')) {
fn = realRequire(decodeURIComponent(target))
} else {
fn = (await realImport(toLoad))
}
} catch (error) {
// See this PR for details: https://github.com/pinojs/thread-stream/pull/34
if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND')) {
fn = realRequire(target)
} else if (error.code === undefined) {
// When bundled with pkg, an undefined error is thrown when called with realImport
fn = realRequire(decodeURIComponent(target))
} else {
throw error
}
Expand Down

1 comment on commit 5072d18

@rokku-x
Copy link

@rokku-x rokku-x commented on 5072d18 Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember the error throws during reallmport variable initialization not during calling. Can you confirm this.

Please sign in to comment.