모듈을 찾을 수 없음: 오류:'fs' 오류를 해결할 수 없음 - 해결됨
네, 앵귤러를 6개에서 8개로 업그레이드했습니다.하지만 저는 여전히 오류가 납니다.
인터넷에서 많은 사용자들에게 도움이 되는 해결책을 찾았습니다.하지만 이 경우에는 도움이 되지 않습니다.
그래서 제 소포.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
}
}
그리고 나의 b.tsconfig.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 중 하나에 어떤 구성을 넣어야 하는 가능한 해결책을 찾았습니다.하지만 저는 그것이 좋은 해결책이 아니라고 생각합니다.가져오기를 모두 제거한 다음 다시 설치하면 구성 가져오기가 사라지기 때문입니다.
감사해요.
좋아, 내가 제거했어요
"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>
그리고 내 소포도.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>
아직도 세 가지 오류가 있습니다.
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.
오류는 다음 때문입니다.angular-cli노드에서 "fs" 및 "path"와 같은 모듈을 지원하지 않습니다. (이슈)
package.json 파일의 루트에 다음을 추가합니다.
"browser": {
"fs": false,
"path": false,
"os": false
}
Angular CLI가 만드는 것과 같은 Angular 앱은 브라우저 앱입니다.fs는 브라우저에서 사용할 수 없고 노드 앱에서만 사용할 수 있습니다.
위해서Webpack > 5
갱신하다webpack.config.js
module.exports = {
...
resolve: {
fallback: {
"fs": false
},
}
}
웹팩 #447과 함께 번들로 제공되는 경우 'fs'를 해결할 수 없습니다.
저에게 해결책은 다음과 같이 웹팩 구성에 추가하는 것이었습니다.
config.node = {
fs: 'empty',
}
NuxtJS를 사용하는 경우 또 다른 솔루션:
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
extend(config, {}) {
config.node = {
fs: 'empty'
}
}
},
NextJS를 사용하는 경우(테스트되지 않은 경우, 주석에서 작동하는지 확인하십시오):
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.node = {
fs: 'empty'
}
return config
},
그 외의 경우 Anjana Silva 게시글을 참고해주시기 바랍니다.패키지 편집.json 파일로 할 수 있습니다!
NextJS 12의 경우: next.config.js
module.exports = (phase, { defaultConfig }) => {
return {
...defaultConfig,
webpack: (config) => {
config.resolve = {
...config.resolve,
fallback: {
"fs": false,
"path": false,
"os": false,
}
}
return config
},
}
}
tl;dr
Node.js를 위해 변환하는 사용자의 경우: addtarget: node에게webpack.config.js파일.
설명.
이것이 Angular 질문이라는 것을 알고 있지만 Node.js용으로 변환하는 사람들은 기본적으로 Node.js에서만 제공되는 모듈이 없는 브라우저 대상으로 웹팩이 변환된다는 것을 기억해야 합니다.만약 당신이 트랜스파일 코드를 실행할 당신의 환경이 Node.js라면, 다음과 같이 구성 파일에 그것을 표시하면 됩니다.target: node.
추가하기만 하면 됩니다.{node:'empty'}당신에게webpack.config파일.
Nuxt를 쓰고 있습니다.JS 제게 도움이 된 것은 @thisisismyname 솔루션을 사용하여 nuxt.config.js에 추가하는 것이었습니다.
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
extend(config, {}) {
config.node = {
fs: 'empty'
}
}
},
동일한 오류가 발생했지만, 네트워크 요청에 액시오스를 사용하고 있기 때문에 실수로 인한 것이었습니다. 앱의 어느 지점에서 redirect를 입력하고 Enter 키를 눌렀고 코드 완료 시 'inport {redirect}'를 "next/dist/next-server/server/api-utils"에서 가져왔습니다. 이 줄을 제거하면 'next build'를 계속할 수 있습니다.
참조를 위해 이 링크를 참조하십시오.
리액터 다음 js를 사용하시는 분들을 위해서요.속달에서 json 자동 가져오기로 인해 발생할 수 있습니다!
import { json } from 'express'
따라서 이 라인이 자동으로 가져온 것이 아닌지 확인하십시오.
라라벨 믹스가 포함된 라라벨 8을 사용하는 모든 사람에게 ^5
mix.webpackConfig({
resolve: {
fallback: { fs: false }
}
});
이것은 웹팩 < 5:mix.webpackConfig({ node: { fs: 'empty', } })
이것을 당신의 것에 추가합니다.webpack.mix.js
이 단계들을 시도해 볼 수 있습니까?
- 삭제
node_modules - 삭제
package-lock.json - 제거한다.
"fs": "0.0.1-security"부터package.json npm install --save
바로 위 하단에 가까운 곳에 추가합니다.
devtool: options.devtool ...
node: { fs: 'empty' },
이렇게 하면 웹 팩이 fs 종속성을 무시하게 됩니다.
예.
resolve: {
modules: ['app', 'node_modules'],
extensions: [
'.js',
'.jsx',
'.react.js',
],
mainFields: [
'browser',
'jsnext:main',
'main',
],
},
node: { fs: 'empty' },
devtool: options.devtool,
target: 'web', // Make web variables accessible to webpack, e.g. window
performance: options.performance || {},
});
fs 서버측을 사용하면 nextJS를 사용할 경우 getStaticProps 등의 기능에서 사용할 수 있습니다.
내가 겪은 문제는 누군가가 추가되었다는 것입니다.node에게tsconfig.spec.json.
제거하면 문제가 해결됩니다.
{
"compilerOptions": {
"types": [
...
"node", // Remove this line
]
}
}
전자의 렌더러 프로세스의 경우 웹팩 구성 파일에서 다음과 같이 대상을 변경합니다.
target: 'electron-renderer'
Electron용 웹팩의 대상 옵션에 대한 자세한 내용은 다음 페이지를 참조하십시오. https://webpack.js.org/configuration/target/
저도 같은 문제가 있습니다.하지만 내 폴더의 이름을 바꾼 후에c#로.csharp, 문제가 사라졌습니다.
Laravel Mix(^4.0)의 경우 다음과 같이 해결했습니다.
mix.webpackConfig({
"node": {
fs: 'empty',
}
});
webpack.mix.js에서
비반응 앱에 대한 웹팩 동작과 웹팩 구성의 외부 객체에 오류 반환을 추가해야 합니다.저는 'react-native-fs'와 'fs' 자체가 오류 로그에 표시되어 있습니다.이를 추가한 다음 외부를 다시 빌드합니다. {'react-native-fs': 'reactNativeFs', 'fs': 'reactNativeFs'}
Angular 내에서 전자를 요구하고 전자 기능을 사용하려고 해서 오류가 발생했습니다.예를 들어, 다음과 같은 작업을 수행하는 대신:
const { dialog } = require('electron');
IPC를 사용하여 전자 프로세스에 메시지를 보냅니다.
import { IpcRenderer, IpcRendererEvent } from 'electron';
애플리케이션(근본 원인)을 고치기만 하면 오류가 사라졌습니다.
예: vscode가 내 상단에 삽입됨index.tsx(CSR) 뭐 그런 거.import register from './api/register'아마도 "자동 comple션"에 의해서일 것입니다. 왜냐하면 실제로는pages/api/register.ts, 그러면 모듈(여기서는 e-메일러가 없음)이 당겨져 'fs' 모듈이 필요합니다.제가 이 잘못된 줄을 지웠더니 오류가 사라졌습니다.
보고된 오류는
...
wait - compiling / (client and server)...
error - ./node_modules/nodemailer/lib/dkim/index.js:10:0
Module not found: Can't resolve 'fs'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/nodemailer/lib/mailer/index.js
./node_modules/nodemailer/lib/nodemailer.js
...
./pages/api/register.ts
./pages/index.tsx
클라이언트/웹 브라우저에는 사용 가능한 'fs' 모듈이 없으므로 컴파일러는 알려진 모듈 목록(또는 그와 유사한 것)에서 제외합니다.
그래서 내 결론은:이 오류가 발생하면 클라이언트 측 렌더링 코드 조각일 가능성이 있으며, 이는 'fs'가 필요한 다른 모듈을 직간접적으로 끌어옵니다.이 경우 "fs: empty" 등을 사용하여 웹팩 구성을 조정합니다.next.config.js- 오류를 발생시킵니다)가 작동할 수도 있지만 실제 문제는 숨길 수도 있습니다.
vuejs/nuxtjs 프로젝트에서 오는 경우 실수로 vue 페이지/구성요소에 추가하지 않았는지 확인합니다.
import { debug } from "webpack";
이것은 제가 추가하고 싶을 때 실수로 추가된 것입니다.debugger내 페이지에 저장하고 내 빌드/프로젝트가 다시 작동하는 것을 제거합니다.
언급URL : https://stackoverflow.com/questions/57161839/module-not-found-error-cant-resolve-fs-error-solved
'codememo' 카테고리의 다른 글
| 디바의 내용을 이미지로 저장하는 방법? (0) | 2023.11.04 |
|---|---|
| 도커 이미지 이름에서 알파인, 제시, 스트레치, 버스터의 차이점은 무엇입니까? (0) | 2023.11.04 |
| Java: org.w3c.dom의 모든 요소에 대해 반복하기에 가장 효율적인 방법입니다.문서? (0) | 2023.11.04 |
| 유형 안전이란 무엇이며 "유형 안전" 대안은 무엇입니까? (0) | 2023.11.04 |
| SQL Server 2005 - 프로그래밍 방식으로 테이블 내보내기(.sql 파일을 실행하여 재구성) (0) | 2023.11.04 |