Closed
Description
- Version:v12.18.0
- Platform:Linux dev 5.3.0-53-generic V8 upgrades and what they mean for versioning #47~18.04.1-Ubuntu SMP Thu May 7 13:10:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem:require
What steps will reproduce the bug?
- Download LTS 12.18.0 from https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz
- Untar compressed file
- Save a js file with the following code: (Let's called it test.js)
console.log(require)
- Run //node-v12.18.0-linux-x64/bin/node test.js
- Node returns error output stating that require is not defined.
How often does it reproduce? Is there a required condition?
All the time.
What is the expected behavior?
The behavior should be similar to node executing the same one liner in REFL interactive shell.
$ node
Welcome to Node.js v12.18.0.
Type ".help" for more information.
> console.log(require)
[Function: require] {
resolve: [Function: resolve] { paths: [Function: paths] },
main: undefined,
extensions: [Object: null prototype] {
'.js': [Function],
'.json': [Function],
'.node': [Function]
},
cache: [Object: null prototype] {}
}
What do you see instead?
$ node test.js
(node:13608) ExperimentalWarning: The ESM module loader is experimental. file:///somedirectory/test.js:1 console.log(require); ^ ReferenceError: require is not defined
Additional information
The issue does not happen in older node versions. See text output below
$ node --version
v8.10.0
$ node test.js
{ [Function: require]
resolve: { [Function: resolve] paths: [Function: paths] },
main:
Module {
id: '.',
exports: {},
parent: null,
filename: '/somedirectory/test.js',
loaded: false,
children: [],
paths:
[ '/somedirectory/node_modules',
...,
...,
'/node_modules' ] },
extensions: { '.js': [Function], '.json': [Function], '.node': [Function] },
cache:
{ '/somedirectory/test.js':
Module {
id: '.',
exports: {},
parent: null,
filename: '/somedirectory/test.js',
loaded: false,
children: [],
paths: [Array] } } }