Repository navigation
[bug] --abort-on-uncaught-exception causes containsModuleSyntax to improperly throw Uncaught SyntaxError: Cannot use import statement outside a module #50878
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Description
Version
20.10.0
Platform
Linux Alpine
Subsystem
No response
What steps will reproduce the bug?
This command works in 20.9.0, but not in 20.10.0, specifically when --abort-on-uncaught-exception opt is passed in:
$ NODE_OPTIONS="--abort-on-uncaught-exception" node_modules/.bin/knex migrate:make test
# outputs
Uncaught SyntaxError: Cannot use import statement outside a moduleThe version of knex:
node_modules/.bin/knex --version
Knex CLI version: 2.4.2
Knex Local version: 2.4.2How often does it reproduce? Is there a required condition?
Fails every time!
What is the expected behavior? Why is that the expected behavior?
The migration was created by knex in 20.9.0
What do you see instead?
Now it fails with this output:
Uncaught SyntaxError: Cannot use import statement outside a module
FROM
Module._extensions..js (node:internal/modules/cjs/loader:1407:23)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/debug@4.3.4_supports-color@9.2.2/node_modules/debug/src/node.js:32:24)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/debug@4.3.4_supports-color@9.2.2/node_modules/debug/src/index.js:9:19)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/lib/execution/transaction.js:4:15)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/lib/client.js:10:21)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/lib/knex-builder/Knex.js:1:16)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/lib/index.js:1:14)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
Object.<anonymous> (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/knex.js:8:14)
Module._compile (node:internal/modules/cjs/loader:1376:14)
Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
Module.load (node:internal/modules/cjs/loader:1207:32)
Module._load (node:internal/modules/cjs/loader:1023:12)
Module.require (node:internal/modules/cjs/loader:1235:19)
require (node:internal/modules/helpers:176:18)
initKnex (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/bin/cli.js:83:16)
async Command.<anonymous> (/app/node_modules/.pnpm/knex@2.4.2_pg@8.11.0/node_modules/knex/bin/cli.js:221:26)Trace/breakpoint trap
Additional information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Activity
KidkArolis commentedon Nov 23, 2023
Let me know if you need more details on how to reproduce, I could perhaps create a small repo to show the issue if it helps.
aduh95 commentedon Nov 23, 2023
Could you produce a repro that doesn't include downloading any external code? If not, you should report it to the dependency you are using.
KidkArolis commentedon Nov 23, 2023
Working on reproducing it in a standalone file, but this behaviour change happens strictly if running this with Node.js 20.10.0:
tjenkinson commentedon Nov 23, 2023
I've put together a repo here: https://github.com/tjenkinson/node-20.10.0-ERR_REQUIRE_ESM-crash
It seems instead of the
ERR_REQUIRE_ESMerror being thrown now when esm isrequire'd it crashes.From the debugger it looks like it might be a crash happening in the internal
containsModuleSyntaxmodule?tjenkinson commentedon Nov 23, 2023
Just pushed a new commit to that repro that changes it slightly. It seems to be when it's a module in
node_modulesthat it trips up.tjenkinson commentedon Nov 23, 2023
Looks like the crash is here:
node/lib/internal/modules/cjs/loader.js
Line 1406 in 4e713a3
And this was added in a9b2535
targos commentedon Nov 23, 2023
Here's a C++ backtrace:
targos commentedon Nov 23, 2023
The crash happens within a TryCatch scope, so it seems like a V8 bug. It shouldn't abort in this case.
targos commentedon Nov 23, 2023
I added some logs to the
PredictExceptionCatcherand it returns here:node/deps/v8/src/execution/isolate.cc
Lines 2437 to 2438 in 4e713a3
/cc @nodejs/cpp-reviewers
joyeecheung commentedon Nov 30, 2023
This looks like a negligence from our side of not disabling aborting temporarily for the syntax check in our ShouldAbortOnUncaughtException callback.
joyeecheung commentedon Nov 30, 2023
cc @nodejs/loaders
anonrig commentedon Dec 1, 2023
@KidkArolis I opened a PR that fixes this issue.
targos commentedon Dec 1, 2023
@joyeecheung how do you explain that
PredictExceptionCatcherdoesn't find the TryCatch scope?joyeecheung commentedon Dec 1, 2023
I think that's for JavaScript
try {} catch {}, notv8::TryCatch.[-]Uncaught SyntaxError: Cannot use import statement outside a module in 20.10.0[/-][+][bug] `--abort-on-uncaught-exception` causes `containsModuleSyntax` to improperly throw `Uncaught SyntaxError: Cannot use import statement outside a module`[/+]