Module not found: Error: Can't resolve 'fs' in

受付中 プログラミング
2024-12-24
masato
Angularを6から8にアップグレードしました。しかし、エラーが発生します。 私はインターネット上で多くのユーザーにとって役立つ解決策を見つけました。しかし、この場合、それは私を助けませんでした。 したがって、私のpackage.jsonファイルは次のようになります。
        {
          "name": "vital10-frontend",
          "version": "0.55.0",
          "license": "Unlicensed",
          "scripts": {
            "ng": "ng",
            "start": "ng serve",
            "hmr": "ng serve --configuration hmr",
            "build": "ng build",
            "build:prod": "npm run sass:prod && npm run vit10prod",
            "build:acc": "npm run sass:prod && npm run vit10acc",
            "build:test": "npm run sass:prod && npm run vit10test",
            "build:dev": "npm run sass:prod && npm run vit10dev",
            "test": "ng test",
            "test:cover": "ng test --code-coverage",
            "lint": "ng lint",
            "e2e": "ng e2e",
            "local": "ng serve -c local",
            "analyze-bundle": "webpack-bundle-analyzer dist/stats.json",
            "postinstall": "node patch-webpack.js",
            "sass:watch": "sass --watch sass:src\\assets",
            "sass:prod": "sass --update -f --style compressed --sourcemap=none sass:src\\assets",
            "vit10dev": "ng build --prod -c vit10dev",
            "vit10test": "ng build --prod -c vit10test",
            "vit10acc": "ng build --prod -c vit10acc",
            "vit10prod": "ng build --prod -c production"
          },
          "private": true,
          "dependencies": {
            "@angular/animations": "^8.1.2",
            "@angular/cdk": "^7.3.7",
            "@angular/common": "^8.1.2",
            "@angular/compiler": "^8.1.2",
            "@angular/core": "^8.1.2",
            "@angular/forms": "^8.1.2",
            "@angular/http": "^7.2.15",
            "@angular/platform-browser": "^8.1.2",
            "@angular/platform-browser-dynamic": "^8.1.2",
            "@angular/platform-server": "^8.1.2",
            "@angular/router": "^8.1.2",
            "@types/chart.js": "^2.7.54",
            "buffer": "^5.2.1",
            "chart.js": "^2.7.2",
            "core-js": "^2.5.7",
            "events": "^3.0.0",
            "fs": "0.0.1-security",
            "jasmine": "^3.1.0",
            "ng2-charts": "^1.6.0",
            "ng2-dragula": "^2.1.1",
            "ng2-pdf-viewer": "^5.0.1",
            "node-sass": "^4.11.0",
            "oidc-client": "^1.5.1",
            "path": "^0.12.7",
            "pdfjs-dist": "^2.0.489",
            "rxjs": "^6.5.2",
            "rxjs-compat": "^6.5.2",
            "stream": "0.0.2",
            "timers": "^0.1.1",
            "web-animations-js": "^2.3.1",
            "zone.js": "^0.9.1"
          },
          "devDependencies": {
            "@angular-devkit/build-angular": "^0.801.2",
            "@angular/cli": "^8.1.2",
            "@angular/compiler-cli": "^8.1.2",
            "@angular/language-service": "^8.1.2",
            "@angularclass/hmr": "^2.1.3",
            "@compodoc/compodoc": "^1.1.10",
            "@types/jasmine": "^3.3.14",
            "@types/node": "^12.6.8",
            "chai": "^4.1.2",
            "codelyzer": "^5.1.0",
            "convert-csv-to-json": "0.0.13",
            "cucumber": "^4.2.1",
            "cucumber-html-reporter": "^5.0.0",
            "cucumber-junit": "^1.7.1",
            "express-static": "^1.2.5",
            "jasmine-core": "^3.4.0",
            "jasmine-reporters": "^2.3.1",
            "jasmine-spec-reporter": "^4.2.1",
            "karma": "^4.2.0",
            "karma-chrome-launcher": "^3.0.0",
            "karma-cli": "^2.0.0",
            "karma-coverage-istanbul-reporter": "^1.2.1",
            "karma-html-reporter": "^0.2.7",
            "karma-jasmine": "^2.0.1",
            "karma-jasmine-html-reporter": "^1.4.2",
            "karma-junit-reporter": "^1.2.0",
            "karma-teamcity-reporter": "^1.1.0",
            "moment": "^2.22.1",
            "prettier": "1.13.4",
            "protractor": "^5.4.2",
            "protractor-beautiful-reporter": "^1.2.1",
            "protractor-cucumber-framework": "^5.0.0",
            "puppeteer": "^1.14.0",
            "request": "^2.87.0",
            "request-promise-native": "^1.0.5",
            "ts-node": "^3.3.0",
            "tslint": "^5.18.0",
            "tslint-angular": "^1.1.2",
            "typescript": "3.4.5",
            "webpack-bundle-analyzer": "^3.3.2",
            "xlsx": "^0.12.13"
          },
          "browser": {
            "fs": false,
            "path": false,
            "os": false,
            "crypto": false,
            "stream": false,
            "http": false,
            "tls": false,
            "zlib": false,
            "https": false,
            "net": false
          }
        }
        
そして私のbtsconfig.jsonファイルは次のようになります:
        {
          "compileOnSave": false,
          "compilerOptions": {
            "outDir": "./dist/out-tsc",
            "baseUrl": "src",
            "sourceMap": true,
            "declaration": false,
            "moduleResolution": "node",
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "target": "es5",
            "typeRoots": [
              "node_modules/@types"
            ],
            "lib": [
              "es2016",
              "dom"
            ]
          },
           "angularCompilerOptions": {
             "enableIvy": false
           }
        }
        
しかし、私はまだこれらのエラーを受け取ります:
        ERROR in ./node_modules/resolve/lib/async.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\resolve\lib'
        ERROR in ./node_modules/resolve/lib/sync.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\resolve\lib'
        ERROR in ./node_modules/resolve/lib/node-modules-paths.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\resolve\lib'
        ERROR in ./node_modules/tslint/lib/utils.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\tslint\lib'
        
node_modulesの1つにいくつかの構成を配置する必要があるという、考えられる解決策を見つけました。しかし、それは良い解決策ではないと思います。すべてのインポートを削除してから再度インストールすると、構成が正しくなります。 ありがとうございました 桶、私は削除しました
         "fs": "0.0.1-security",
        
すべてのパック(node_modules)を削除し、npmインストールを実行しました。 しかし今、私はこれを手に入れました:
        (node:13880) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added. Use emitter.setMaxListeners() to increase limit
        Binary found at C:\Source\nien\vital10-frontend\node_modules\node-sass\vendor\win32-x64-64\binding.node
        Testing binary
        Binary is fine
        
        > vital10-frontend@0.55.0 postinstall C:\Source\nien\vital10-frontend
        > node patch-webpack.js
        
        internal/modules/cjs/loader.js:638
            throw err;
            ^
        
        Error: Cannot find module 'C:\Source\nien\vital10-frontend\patch-webpack.js'
            at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
            at Function.Module._load (internal/modules/cjs/loader.js:562:25)
            at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
            at startup (internal/bootstrap/node.js:283:19)
            at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
        npm ERR! code ELIFECYCLE
        npm ERR! errno 1
        npm ERR! vital10-frontend@0.55.0 postinstall: `node patch-webpack.js`
        npm ERR! Exit status 1
        npm ERR!
        npm ERR! Failed at the vital10-frontend@0.55.0 postinstall script.
        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
        
        npm ERR! A complete log of this run can be found in:
        npm ERR!     C:\Users\nien\AppData\Roaming\npm-cache\_logs\2019-07-23T10_25_46_184Z-debug.log
        PS C:\Source\nien\vital10-frontend>
        
そして、私のpackage.jsonファイルは次のようになります。
        {
          "name": "vital10-frontend",
          "version": "0.55.0",
          "license": "Unlicensed",
          "scripts": {
            "ng": "ng",
            "start": "ng serve",
            "hmr": "ng serve --configuration hmr",
            "build": "ng build",
            "build:prod": "npm run sass:prod && npm run vit10prod",
            "build:acc": "npm run sass:prod && npm run vit10acc",
            "build:test": "npm run sass:prod && npm run vit10test",
            "build:dev": "npm run sass:prod && npm run vit10dev",
            "test": "ng test",
            "test:cover": "ng test --code-coverage",
            "lint": "ng lint",
            "e2e": "ng e2e",
            "local": "ng serve -c local",
            "analyze-bundle": "webpack-bundle-analyzer dist/stats.json",
            "postinstall": "node patch-webpack.js",
            "sass:watch": "sass --watch sass:src\\assets",
            "sass:prod": "sass --update -f --style compressed --sourcemap=none sass:src\\assets",
            "vit10dev": "ng build --prod -c vit10dev",
            "vit10test": "ng build --prod -c vit10test",
            "vit10acc": "ng build --prod -c vit10acc",
            "vit10prod": "ng build --prod -c production"
          },
          "private": true,
          "dependencies": {
            "@angular/animations": "^8.1.2",
            "@angular/cdk": "^7.3.7",
            "@angular/common": "^8.1.2",
            "@angular/compiler": "^8.1.2",
            "@angular/core": "^8.1.2",
            "@angular/forms": "^8.1.2",
            "@angular/http": "^7.2.15",
            "@angular/platform-browser": "^8.1.2",
            "@angular/platform-browser-dynamic": "^8.1.2",
            "@angular/platform-server": "^8.1.2",
            "@angular/router": "^8.1.2",
            "@types/chart.js": "^2.7.54",
            "buffer": "^5.2.1",
            "chart.js": "^2.7.2",
            "core-js": "^2.5.7",
            "events": "^3.0.0",
            "jasmine": "^3.1.0",
            "ng2-charts": "^1.6.0",
            "ng2-dragula": "^2.1.1",
            "ng2-pdf-viewer": "^5.0.1",
            "node-sass": "^4.11.0",
            "oidc-client": "^1.5.1",
            "path": "^0.12.7",
            "pdfjs-dist": "^2.0.489",
            "rxjs": "^6.5.2",
            "rxjs-compat": "^6.5.2",
            "stream": "0.0.2",
            "timers": "^0.1.1",
            "web-animations-js": "^2.3.1",
            "zone.js": "^0.9.1"
          },
          "devDependencies": {
            "@angular-devkit/build-angular": "^0.801.2",
            "@angular/cli": "^8.1.2",
            "@angular/compiler-cli": "^8.1.2",
            "@angular/language-service": "^8.1.2",
            "@angularclass/hmr": "^2.1.3",
            "@compodoc/compodoc": "^1.1.10",
            "@types/jasmine": "^3.3.14",
            "@types/node": "^12.6.8",
            "chai": "^4.1.2",
            "codelyzer": "^5.1.0",
            "convert-csv-to-json": "0.0.13",
            "cucumber": "^4.2.1",
            "cucumber-html-reporter": "^5.0.0",
            "cucumber-junit": "^1.7.1",
            "express-static": "^1.2.5",
            "jasmine-core": "^3.4.0",
            "jasmine-reporters": "^2.3.1",
            "jasmine-spec-reporter": "^4.2.1",
            "karma": "^4.2.0",
            "karma-chrome-launcher": "^3.0.0",
            "karma-cli": "^2.0.0",
            "karma-coverage-istanbul-reporter": "^1.2.1",
            "karma-html-reporter": "^0.2.7",
            "karma-jasmine": "^2.0.1",
            "karma-jasmine-html-reporter": "^1.4.2",
            "karma-junit-reporter": "^1.2.0",
            "karma-teamcity-reporter": "^1.1.0",
            "moment": "^2.22.1",
            "prettier": "1.13.4",
            "protractor": "^5.4.2",
            "protractor-beautiful-reporter": "^1.2.1",
            "protractor-cucumber-framework": "^5.0.0",
            "puppeteer": "^1.14.0",
            "request": "^2.87.0",
            "request-promise-native": "^1.0.5",
            "ts-node": "^3.3.0",
            "tslint": "^5.18.0",
            "tslint-angular": "^1.1.2",
            "typescript": "3.4.5",
            "webpack-bundle-analyzer": "^3.3.2",
            "xlsx": "^0.12.13"
          },
          "browser": {
            "fs": false,
            "path": false,
            "os": false,
            "crypto": false,
            "stream": false,
            "http": false,
            "tls": false,
            "zlib": false,
            "https": false,
            "net": false
          }
        }
        
まだこのエラーを取得します:
        (node:15956) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added. Use emitter.setMaxListeners() to increase limit
        internal/modules/cjs/loader.js:638
            throw err;
            ^
        
        Error: Cannot find module 'C:\Source\nien\vital10-frontend\patch-webpack.js'
            at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
            at Function.Module._load (internal/modules/cjs/loader.js:562:25)
            at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
            at startup (internal/bootstrap/node.js:283:19)
            at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
        npm ERR! code ELIFECYCLE
        npm ERR! errno 1
        npm ERR! vital10-frontend@0.55.0 postinstall: `node patch-webpack.js`
        npm ERR! Exit status 1
        npm ERR!
        npm ERR! Failed at the vital10-frontend@0.55.0 postinstall script.
        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
        
        npm ERR! A complete log of this run can be found in:
        npm ERR!     C:\Users\nien\AppData\Roaming\npm-cache\_logs\2019-07-23T10_59_04_891Z-debug.log
        PS C:\Source\nien\vital10-frontend>
        
私はまだこの3つのエラーを取得します
        ERROR in ./node_modules/resolve/lib/async.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\resolve\lib'
        ERROR in ./node_modules/resolve/lib/sync.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\resolve\lib'
        ERROR in ./node_modules/tslint/lib/utils.js
        Module not found: Error: Can't resolve 'fs' in 'C:\Source\nien\vital10-frontend\node_modules\tslint\lib'
        i 「wdm」: Failed to compile.
        
回答一覧
"fs": "0.0.1-security",package.jsonから削除してみましたか?
masato
「npm監査修正」を実行できますか
masato
はい、実行できますが、解決します
masato
エラーは、angular-cli「fs」や「path」などのノードのモジュールをサポートしていないためです。(発行) 「package.json」ファイルのルートに以下を追加します。
        "browser": {
          "fs": false,
          "path": false,
          "os": false
        }
        
これが誰かに役立つことを願っています。 ありがとう。
masato
まだエラーが発生します。Angular 10を使用しています。Electron10.1コードをどこに貼り付ける必要がありますか?ルートノードで?または「依存関係」ノード内?
masato
packages.jsonファイルを確認しましたか?
masato
Angular10テストでfirebase/testingモジュールを使用しようとしたときにこのエラーが発生しました。これで解決しましたが、ライブラリをさらにいくつか含める必要があったため、次のようになりました。"browser": { "fs": false, "path": false, "os": false, "net": false, "tls": false }
masato
ファイルに名前が付けられpackage.jsonていませんpackages.jsonか?(単数形)-Webpack5では動作しません。
masato
package.json直前のルートに貼り付けて、scripts動作するようになりました。ありがとう!
masato