JavaScript and memory leaks[z]

本文探讨了JavaScript中常见的几种内存泄漏模式,包括通过属性创建的循环引用、使用封装器模式创建的循环引用、作为闭包函数的事件监听器导致的泄漏等,并提供了避免泄漏的方法。

From:http://www.javascriptkit.com/javatutors/closuresleak/index3.shtml

All of the patterns shown below are described in detail in Justing's article. I'm going through them just for the sake of completeness:

[Exhibit 5 - Circular reference because of expando property]

<html>
<head>
<script type="text/javascript">
    var myGlobalObject;

    function SetupLeak(){
        //Here a reference created from the JS World 
        //to the DOM world.
        myGlobalObject=document.getElementById("LeakedDiv");

        //Here DOM refers back to JS World; 
        //hence a circular reference.
        //The memory will leak if not handled properly.
        document.getElementById("LeakedDiv").expandoProperty=
                                               myGlobalObject;
    }
</script>
</head>
<body οnlοad="SetupLeak()">
<div id="LeakedDiv"></div>
</body>
</html>

Here the global variable myGlobalObject refers to the DOM element LeakDiv; at the same time LeakDiv refers to the global object through its expandoProperty. The situation looks like this:

The above pattern will leak due to the circular reference created between a DOM node and a JS element.

Since the JScript garbage collector is a mark and sweep GC, you may think that it would handle circular references. And in fact it does. However this circular reference is between the DOM and JS worlds. DOM and JS have separate garbage collectors. Therefore they cannot clean up memory in situations like the above.

Another way to create a circular reference is to encapsulate the DOM element as a property of a global object:

[Exhibit 6 - Circular reference using an Encapsulator pattern]

<html>
<head>
<script type="text/javascript">
function Encapsulator(element){
    //Assign our memeber
    this.elementReference = element;

    // Makea circular reference
    element.expandoProperty = this;
}

function SetupLeak() {
    //This leaks
    new Encapsulator(document.getElementById("LeakedDiv"));
}
</script>
</head>
<body οnlοad="SetupLeak()">
<div id="LeakedDiv"></div>
</body>
</html>

Here is how it looks like:

However, the most common usage of closures over DOM nodes is event attachment. The following code will leak:

[Exhibit 7 - Adding an event listener as a closure function]

<html>
<head>
<script type="text/javascript">
window.οnlοad=function(){
    // obj will be gc'ed as soon as 
    // it goes out of scope therefore no leak.
    var obj = document.getElementById("element");
    
    // this creates a closure over "element"
    // and will leak if not handled properly.
    obj.οnclick=function(evt){
        ... logic ...
    };
};
</script>
</head>
<body>
<div id="element"></div>
</body>
</html>

Here is a diagram describing the closure which creates a circular reference between the DOM world and the JS world.

The above pattern will leak due to closure. Here the closure's global variable obj is referring to the DOM element. In the mean time, the DOM element holds a reference to the entire closure. This generates a circular reference between the DOM and the JS worlds. That is the cause of leakage.

When we remove closure we see that the leak has gone:

[Exhibit 8- Leak free event registration - No closures were harmed]

<html>
<head>
<script type="text/javascript">
window.οnlοad=function(){
    // obj will be gc'ed as soon as 
    // it goes out of scope therefore no leak.
    var obj = document.getElementById("element");
    obj.οnclick=element_click;
};

//HTML DOM object "element" refers to this function
//externally
function element_click(evt){
    ... logic ...
}
</script>
</head>
<body>
<div id="element"></div>
</body>
</html>

Here is the diagram for the above code piece:

This pattern will not leak because as soon as the function window.onload finishes execution, the JS object obj will be marked for garbage collection. So there won't be any reference to the DOM node on the JS side.

And the last but not the least leak pattern is the "cross-page leak":

[Exhibit 10 - Cross Page Leak]

<html>
<head>
<script type="text/javascript">
function LeakMemory(){
    var hostElement = document.getElementById("hostElement");
    // Do it a lot, look at Task Manager for memory response
    for(i = 0; i < 5000; i++){
        var parentDiv =
        document.createElement("<div onClick='foo()'>");

        var childDiv =
        document.createElement("<div onClick='foo()'>");

        // This will leak a temporary object
        parentDiv.appendChild(childDiv);
        hostElement.appendChild(parentDiv);
        hostElement.removeChild(parentDiv);
        parentDiv.removeChild(childDiv);
        parentDiv = null;
        childDiv = null;
    }
    hostElement = null;
}
</script>
</head>
<body>
<input type="button" 
       value="Memory Leaking Insert" οnclick="LeakMemory()" />
<div id="hostElement"></div>
</body>
</html>

Since we observe memory leakage even in Exhibit 1, it is not surprising that this pattern leaks. Here is what happens: When we append childDiv to parentDiv, a temporary scope from childDiv to parentDiv is created which will leak a temporary script object. Note that document.createElement("<div onClick='foo()'>"); is a non-standard method of event attachment.

Simply using the "best practices" is not enough (as Justing has mentioned in his article as well). One should also adhere to standards as much as possible. If not, he may not have a single clue about what went wrong with the code that was working perfectly a few hours ago (which had just crashed unexpectedly).

Anyway, let us re-order our insertion. The code below will not leak:

[Exhibit 11 - DOM insertion re-ordered - no leaks]

<html>
<head>
<script type="text/javascript">
function LeakMemory(){
    var hostElement = document.getElementById("hostElement");
    // Do it a lot, look at Task Manager for memory response
    for(i = 0; i < 5000; i++){
        var parentDiv =
          document.createElement("<div onClick='foo()'>");

        var childDiv =
          document.createElement("<div onClick='foo()'>");

        hostElement.appendChild(parentDiv);
        parentDiv.appendChild(childDiv);
        parentDiv.removeChild(childDiv);
        hostElement.removeChild(parentDiv);

        parentDiv = null;
        childDiv = null;
    }
    hostElement = null;
}
</script>
</head>
<body>
<input type="button" 
       value="Memory Leaking Insert" οnclick="LeakMemory()" />
<div id="hostElement"></div>
</body>
</html>

We should keep in mind that, although it is the market leader, IE is not the only browser in the world. And writing IE-specific non-standard code is a bad practice of coding. The counter-argument is true as well. I mean, saying "Mozilla is the best browser so I write Mozilla-specific code; I don't care what the heck happens to the rest" is an equally bad attitude. You should enlarge your spectrum as much as possible. As a corollary, you should write standards-compatible code to the highest extent, whenever possible.

Writing, "backwards compatible" code is "out" nowadays. The "in" is writing "forward compatible" (also known as standards compatible) code which will run now and in the future, in current and in future browsers, here and on the moon.

npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.org/mas-creator-admin - Not found npm ERR! 404 npm ERR! 404 'mas-creator-admin@0.1.0' is not in this registry. npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url. npm ERR! A complete log of this run can be found in: npm ERR! D:\nodejs\node_cache\_logs\2025-03-07T18_08_37_097Z-debug-0.log PS D:\zuoye\yimiao\client> npm install --save-dev @vue/cli-service npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. npm WARN deprecated osenv@0.1.5: This package is no longer supported. npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it . Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm WARN deprecated npmlog@5.0.1: This package is no longer supported. npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm WARN deprecated move-concurrently@1.0.1: This package is no longer supported. npm WARN deprecated npmlog@4.1.2: This package is no longer supported. npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm WARN deprecated figgy-pudding@3.5.2: This module is no longer supported. npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported o
03-10
PS D:\系统代码\qianduan> npm install --package-lock --package-lock-version=1 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@3. I'll try to do my best with it! (node:7240) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. (Use `node --trace-deprecation ...` to show where the warning was created) npm WARN deprecated eslint@7.32.0: This version is no longer supported. Please see https://eslint.org/version-support for other options. npm WARN deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm WARN deprecated @humanwhocodes/config-array@0.5.0: Use @eslint/config-array instead npm WARN deprecated consolidate@0.15.1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm WARN deprecated @humanwhocodes/object-schema@1.2.1: Use @eslint/object-schema instead npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated @types/minimatch@6.0.0: This is a stub types definition. minimatch provides its own type definitions, so you do not need this installed. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\chokidar\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN acorn-import-phases@1.0.4 requires a peer of acorn@^8.14.0 but none is installed. You must install peer dependencies yourself. npm WARN @vue/eslint-config-typescript@9.1.0 requires a peer of eslint-plugin-vue@^8.0.1 but none is installed. You must install peer dependencies yourself. npm WARN The package eslint-plugin-vue is included as both a dev and production dependency. npm WARN The package less is included as both a dev and production dependency. npm WARN The package less-loader is included as both a dev and production dependency. npm ERR! code EPERM npm ERR! syscall mkdir npm ERR! path D:\系统代码\qianduan\node_modules npm ERR! errno -4048 npm ERR! Error: EPERM: operation not permitted, mkdir 'D:\系统代码\qianduan\node_modules' npm ERR! [OperationalError: EPERM: operation not permitted, mkdir 'D:\系统代码\qianduan\node_modules'] { npm ERR! cause: [Error: EPERM: operation not permitted, mkdir 'D:\系统代码\qianduan\node_modules'] { npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'mkdir', npm ERR! path: 'D:\\系统代码\\qianduan\\node_modules' npm ERR! }, npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'mkdir', npm ERR! path: 'D:\\系统代码\\qianduan\\node_modules', npm ERR! parent: '@babel/highlight' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It's possible that the file was already in use (by a text editor or antivirus), npm ERR! or that you lack permissions to access it. npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\asus\AppData\Roaming\npm-cache\_logs\2025-09-24T09_43_01_068Z-debug.log PS D:\系统代码\qianduan>
最新发布
09-25
PS C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp> npm install Debugger attached. npm warn deprecated lodash.template@4.5.0: This package is deprecated. Use https://socket.dev/npm/package/eta instead. npm warn deprecated shvl@2.0.3: older versions vulnerable to prototype pollution npm warn deprecated docsearch.js@2.6.3: This package has been deprecated and is no longer maintained. Please use @docsearch/js. npm warn deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility npm warn deprecated q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. npm warn deprecated npm warn deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) npm warn deprecated figgy-pudding@3.5.2: This module is no longer supported. npm warn deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm warn deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm warn deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm warn deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm warn deprecated har-validator@5.1.5: this library is no longer supported npm warn deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. npm warn deprecated gauge@2.7.4: This package is no longer supported. npm warn deprecated osenv@0.1.5: This package is no longer supported. npm warn deprecated are-we-there-yet@1.1.7: This package is no longer supported. npm warn deprecated npmlog@4.1.2: This package is no longer supported. npm warn deprecated fstream@1.0.12: This package is no longer supported. npm warn deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap. npm warn deprecated fs-write-stream-atomic@1.0.10: This package is no longer supported. npm warn deprecated copy-concurrently@1.0.5: This package is no longer supported. npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm warn deprecated move-concurrently@1.0.1: This package is no longer supported. npm warn deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated consolidate@0.15.1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog npm warn deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained npm warn deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained npm warn deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 npm warn deprecated @hapi/joi@15.1.1: Switch to 'npm install joi' npm warn deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained npm warn deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm warn deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address' npm warn deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm warn deprecated webpack-chain@4.12.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported npm warn deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest npm warn deprecated @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead. npm warn deprecated @babel/plugin-proposal-optional-catch-binding@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead. npm warn deprecated @babel/plugin-proposal-json-strings@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-json-strings instead. npm warn deprecated @babel/plugin-proposal-unicode-property-regex@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-unicode-property-regex instead. npm warn deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead. npm warn deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm warn deprecated vuex-persistedstate@3.2.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated vue-i18n@8.28.2: Vue I18n v8.x has reached EOL and is no longer actively maintained. About maintenance status, see https://vue-i18n.intlify.dev/guide/maintenance.html npm warn deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates. npm warn deprecated eslint-loader@3.0.4: This loader has been deprecated. Please use eslint-webpack-plugin npm warn deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js. npm warn deprecated node-sass@4.14.1: Node Sass is no longer supported. Please use `sass` or `sass-embedded` instead. npm warn deprecated axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410 npm warn deprecated eslint@5.16.0: This version is no longer supported. Please see https://eslint.org/version-support for other options. npm warn deprecated iscroll@5.2.0: deprecated npm warn deprecated mkdirp@0.3.0: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.) npm warn deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated glob@7.1.7: Glob versions prior to v9 are no longer supported npm warn deprecated vue@2.7.16: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details. npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported npm warn deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn cleanup Failed to remove some directories [ npm warn cleanup [ npm warn cleanup '\\\\?\\C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\@hapi'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@hapi' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup '\\\\?\\C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vue', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\@vue\compiler-core\node_modules'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vue\\compiler-core\\node_modules' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup '\\\\?\\C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vuepress', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\@vuepress'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vuepress' npm warn cleanup } npm warn cleanup ] npm warn cleanup ] npm error code 1 npm error path C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\node-sass npm error command failed npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js npm error Building: C:\Program Files\nodejs\node.exe C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= npm error Debugger attached. npm error Debugger attached. npm error gyp info it worked if it ends with ok npm error gyp verb cli [ npm error gyp verb cli 'C:\\Program Files\\nodejs\\node.exe', npm error gyp verb cli 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\node-gyp\\bin\\node-gyp.js', npm error gyp verb cli 'rebuild', npm error gyp verb cli '--verbose', npm error gyp verb cli '--libsass_ext=', npm error gyp verb cli '--libsass_cflags=', npm error gyp verb cli '--libsass_ldflags=', npm error gyp verb cli '--libsass_library=' npm error gyp verb cli ] npm error gyp info using node-gyp@3.8.0 npm error gyp info using node@24.3.0 | win32 | x64 npm error gyp verb command rebuild [] npm error gyp verb command clean [] npm error gyp verb clean removing "build" directory npm error gyp verb command configure [] npm error gyp verb check python checking for Python executable "python2" in the PATH npm error gyp verb `which` failed Error: not found: python2 npm error gyp verb `which` failed at getNotFoundError (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:13:12) npm error gyp verb `which` failed at F (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:68:19) npm error gyp verb `which` failed at E (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:80:29) npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:89:16 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\index.js:42:5 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\windows.js:36:5 npm error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:189:21) npm error gyp verb `which` failed python2 Error: not found: python2 npm error gyp verb `which` failed at getNotFoundError (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:13:12) npm error gyp verb `which` failed at F (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:68:19) npm error gyp verb `which` failed at E (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:80:29) npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:89:16 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\index.js:42:5 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\windows.js:36:5 npm error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:189:21) { npm error gyp verb `which` failed code: 'ENOENT' npm error gyp verb `which` failed } npm error gyp verb check python checking for Python executable "python" in the PATH npm error gyp verb `which` succeeded python C:\Python313\python.EXE npm error (node:3656) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. npm error (Use `node --trace-deprecation ...` to show where the warning was created) npm error gyp ERR! configure error npm error gyp ERR! stack Error: Command failed: C:\Python313\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3]; npm error gyp ERR! stack File "<string>", line 1 npm error gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3]; npm error gyp ERR! stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ npm error gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? npm error gyp ERR! stack npm error gyp ERR! stack at genericNodeError (node:internal/errors:983:15) npm error gyp ERR! stack at wrappedFn (node:internal/errors:537:14) npm error gyp ERR! stack at ChildProcess.exithandler (node:child_process:415:12) npm error gyp ERR! stack at ChildProcess.emit (node:events:507:28) npm error gyp ERR! stack at maybeClose (node:internal/child_process:1101:16) npm error gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:305:5) npm error gyp ERR! System Windows_NT 10.0.26100 npm error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" npm error gyp ERR! cwd C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\node-sass npm error gyp ERR! node -v v24.3.0 npm error gyp ERR! node-gyp -v v3.8.0 npm error gyp ERR! not ok npm error Waiting for the debugger to disconnect... npm error Build failed with error code: 1 npm error Waiting for the debugger to disconnect... npm error A complete log of this run can be found in: D:\node\node_cache\_logs\2025-08-22T05_02_59_796Z-debug-0.log Waiting for the debugger to disconnect...
08-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值