File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 4
4
* SPDX-License-Identifier: MIT
5
5
*/
6
6
7
- // These modules will usually be used on Node.js.
8
- var fs = require ( 'fs' ) ;
9
- var nodePath = require ( 'path' ) ;
7
+ // These modules will usually be used on Node.js. Load them eagerly to avoid
8
+ // the complexity of lazy-loading. However, for now we must guard on require()
9
+ // actually existing: if the JS is put in a .mjs file (ES6 module) and run on
10
+ // node, then we'll detect node as the environment and get here, but require()
11
+ // does not exist (since ES6 modules should use |import|). If the code actually
12
+ // uses the node filesystem then it will crash, of course, but in the case of
13
+ // code that never uses it we don't want to crash here, so the guarding if lets
14
+ // such code work properly. See discussion in
15
+ // https://github.com/emscripten-core/emscripten/pull/17851
16
+ var fs , nodePath ;
17
+ if ( typeof require === 'function' ) {
18
+ fs = require ( 'fs' ) ;
19
+ nodePath = require ( 'path' ) ;
20
+ }
10
21
11
22
read_ = ( filename , binary ) => {
12
23
#if SUPPORT_BASE64_EMBEDDING
You can’t perform that action at this time.
0 commit comments