Skip to content

Commit 7211890

Browse files
committed
Fix checks for nodejs and/or the require function
The check for `require` was being applied even in the case that it wasn't needed. The check for node, when running under the shell environment was out of date with the node check that we use to define ENVIRONMENT_IS_NODE and should not have been checking for require (which is not always present under node these days). Fixes: #15022
1 parent 73c20f6 commit 7211890

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/shell.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ var nodeFS;
158158
var nodePath;
159159

160160
if (ENVIRONMENT_IS_NODE) {
161-
#if ENVIRONMENT
161+
if (ENVIRONMENT_IS_WORKER) {
162162
#if ASSERTIONS
163-
if (!(typeof process === 'object' && typeof require === 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
164-
#endif
163+
if ((!typeof process === 'object' && typeof require === 'function') {
164+
throw new Error("node's require function not found, but is needed in this configuration");
165+
}
165166
#endif
166-
if (ENVIRONMENT_IS_WORKER) {
167167
scriptDirectory = require('path').dirname(scriptDirectory) + '/';
168168
} else {
169169
scriptDirectory = __dirname + '/';
@@ -232,10 +232,14 @@ if (ENVIRONMENT_IS_NODE) {
232232
#if ENVIRONMENT_MAY_BE_SHELL || ASSERTIONS
233233
if (ENVIRONMENT_IS_SHELL) {
234234

235-
#if ENVIRONMENT
236-
#if ASSERTIONS
237-
if ((typeof process === 'object' && typeof require === 'function') || typeof window === 'object' || typeof importScripts === 'function') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
238-
#endif
235+
#if ENVIRONMENT && ASSERTIONS
236+
if ((typeof process === 'object'
237+
&& typeof process.versions === 'object'
238+
&& typeof process.versions.node === 'string') /* NODE */
239+
|| typeof window === 'object' /* WEB */
240+
|| typeof importScripts === 'function' /* WORKER */) {
241+
throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
242+
}
239243
#endif
240244

241245
if (typeof read != 'undefined') {

0 commit comments

Comments
 (0)