-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: clarify CJS global-like variables not defined error message
Fixes: #33741 PR-URL: #37852 Reviewed-By: Guy Bedford <[email protected]>
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/es-module/test-esm-undefined-cjs-global-like-variables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
const { pathToFileURL } = require('url'); | ||
|
||
assert.rejects( | ||
import('data:text/javascript,require;'), | ||
/require is not defined in ES module scope, you can use import instead$/ | ||
).then(common.mustCall()); | ||
assert.rejects( | ||
import('data:text/javascript,exports={};'), | ||
/exports is not defined in ES module scope$/ | ||
).then(common.mustCall()); | ||
|
||
assert.rejects( | ||
import('data:text/javascript,require_custom;'), | ||
/^(?!in ES module scope)(?!use import instead).*$/ | ||
).then(common.mustCall()); | ||
|
||
const pkgUrl = pathToFileURL(fixtures.path('/es-modules/package-type-module/')); | ||
assert.rejects( | ||
import(new URL('./cjs.js', pkgUrl)), | ||
/use the '\.cjs' file extension/ | ||
).then(common.mustCall()); | ||
assert.rejects( | ||
import(new URL('./cjs.js#target', pkgUrl)), | ||
/use the '\.cjs' file extension/ | ||
).then(common.mustCall()); | ||
assert.rejects( | ||
import(new URL('./cjs.js?foo=bar', pkgUrl)), | ||
/use the '\.cjs' file extension/ | ||
).then(common.mustCall()); | ||
assert.rejects( | ||
import(new URL('./cjs.js?foo=bar#target', pkgUrl)), | ||
/use the '\.cjs' file extension/ | ||
).then(common.mustCall()); | ||
|
||
assert.rejects( | ||
import('data:text/javascript,require;//.js'), | ||
/^(?!use the '\.cjs' file extension).*$/ | ||
).then(common.mustCall()); |