모듈을 찾을 수 없음: 오류:'crypto'를 확인할 수 없습니다.
실행 시 다음 오류 목록이 표시됩니다.ng serve
.
제 패키지 JSON은 다음과 같습니다.
{ "name": "ProName", "version": "0.0.0", "scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e" }, "private": true, "dependencies": {
"@angular-devkit/build-angular": "~0.12.0",
"@angular/animations": "5.2.10",
"@angular/common": "5.2.10",
"@angular/compiler": "5.2.10",
"@angular/compiler-cli": "5.2.10",
"@angular/core": "5.2.10",
"@angular/forms": "5.2.10",
"@angular/platform-browser": "5.2.10",
"@angular/platform-browser-dynamic": "5.2.10",
"@angular/router": "5.2.10",
"@types/dotenv": "^4.0.3",
"@types/errorhandler": "0.0.32",
"@types/express": "^4.16.0",
"@types/node": "^10.5.1",
"apostille-library": "^7.1.0",
"core-js": "^2.5.4",
"dotenv": "^6.0.0",
"errorhandler": "^1.5.0",
"express": "^4.16.0",
"nem2-sdk": "^0.9.7",
"rxjs": "~6.3.3",
"stream": "0.0.2",
"tslib": "^1.9.0",
"typescript": "^2.9.2",
"zone.js": "~0.8.26" } }
표시되는 오류:
./node_modules/aws-sign2/index.js 모듈에서 오류를 찾을 수 없습니다. 오류:'/Users/MYPC/Documents/Myproj/ProName/node_modules/aws4.js 모듈의 'crypto' 오류를 확인할 수 없습니다. 오류:./node_modules/ecc-jsbn/index.js 모듈의 '/Users/MYPC/Documents/Myproj/ProName/node_modules/aws4' 오류에서 'crypto'를(를) 확인할 수 없습니다. 오류:./node_modules/http-signature/lib/verify.js 모듈의 '/Users/MYPC/Documents/Myproj/ProName/node_modules/ecc-jsbn' 오류에서 'crypto'를(를) 확인할 수 없습니다. 오류:./node_modules/http-signature/lib/signer.js 모듈의 '/Users/MYPC/Documents/Myproj/ProName/node_modules/http-signature/lib' 오류에서 'crypto'을(를) 확인할 수 없습니다. 오류:./node_modules/nem-sdk/build/external/nacl-fast.js 모듈의 '/Users/MYPC/Documents/Myproj/ProName/node_modules/http-signature/lib' 오류에서 'crypto'를(으)'를(를) 확인할 수 없습니다. 오류:'/Users/MYPC/Documents/Myproj/ProName/node_modules/nem-sdk/build/external'에서 'crypto'를(를) 확인할 수 없습니다. /node_modules/node-sdk/node_modules/aws-sign2/index.js
최근에 실험하던 작은 프로젝트에서 다른 라이브러리(tiff.js)를 사용하려다가 비슷한 문제에 부딪혔습니다.
제가 이 문제를 해결하는 방법은 제 패키지에 다음 사항을 추가하는 것이었습니다.json 파일, 바로 뒤에.devDependencies
부분.
"devDependencies": {
...
},
"browser": {
"crypto": false
}
응용프로그램에서 라이브러리를 사용하려고 할 때 이 문제는 아무런 악영향을 미치지 않는 것으로 보입니다.
이 설정을 해당 프로젝트의 tsconfig.json 파일에 추가하면 이 경고가 해결됩니다.
"compilerOptions": {
"baseUrl": "./",
"paths": {
"crypto": [
"node_modules/crypto-js"
]
}
R 좋아해요. 리차드의 대답이지만, 좀 더 많은 정보를 제공하는 것이 유용할 것이라고 생각했습니다.
이것은 Angular의 알려진 문제이며 Angular CLI dev 팀은 버그가 아닌 기능이라고 생각하는 것 같습니다.저뿐만 아니라 이 문제 스레드의 다른 개발자들도 동의하지 않습니다.그 스레드의 기여자들은 몇 가지 해결 방법을 제공했지만, 제 프로젝트는 R을 구현하기 전까지 성공적으로 컴파일되지 않았습니다.리차드의 해결책.하지만 저는 이전의 변경 사항을 되돌리지 않았기 때문에 tacnoman과 Grand Schtrompf의 수정 사항은 다른 사람들에게 유용할 수 있습니다.
여기 있는 clovis1122와 같은 일부 사람들과 해당 이슈 스레드의 다른 사람들은 웹 앱이 왜 이러한 라이브러리에 대한 액세스를 필요로 하는지, 왜 서버 측에서 필요한 작업을 대신 완료할 수 없는지에 대해 의문을 제기했습니다.모두를 대변할 수는 없지만, 제 사용 사례는 사용자 계정을 인증할 때 Strapi가 클라이언트가 디코딩해야 하는 JSON 웹 토큰 문자열로 응답하는 것입니다.필요한 라이브러리가 다음에 따라 달라지기 때문입니다.crypto
그리고.stream
이러한 종속성을 사용할 수 없는 경우 JWT 만료 시간을 추출할 수 없습니다.
R에서 추론하는 데 어려움을 겪는 사람이 있을 경우.리차드의 대답은 "x를 해결할 수 없음" 오류에 나타나는 종속성을 거짓으로 설정해야 합니다.예를 들어, 내 패키지의 중요한 부분입니다.json은 다음과 같습니다.
"browser": {
"crypto": false,
"stream": false
}
저는 Tarique Ahmed가 그의 답변에서 쓴 것에 대해 더 자세히 설명할 것이라고 생각했습니다.
코드에 다음 줄이 있는 npm 모듈을 사용하고 있었습니다.
const crypto = require('crypto');
추가할 수 없습니다.
"browser": {
"crypto": false
}
json 에 에왜하.crypto
패키지는 빌드의 일부여야 합니다.
Angular는 에서 Angular를 한 것으로 .crypto-browserify
대신포가 아닌 crypto
.
다을에추다에 합니다.tsconfig.json
에 파은빌다사지시합니다록도를 합니다.crypto-browserify
마다 crypto
필수 항목입니다. 저도 있었습니다.stream
package
"paths": {
"crypto": [
"node_modules/crypto-browserify"
],
"stream": [
"node_modules/stream-browserify"
]
}
웹 팩 5로 업그레이드한 경우 웹 팩 구성 파일에 다음을 추가해야 합니다.
resolve: {
fallback: { crypto: false },
},
Angular 11과 crypto-js 4에서 동일한 문제가 발생한 후(그리고 수동으로 tsconfig.json의 경로를 설정) crypto-js를 버전 3.1.9-1로 롤백하여 문제를 해결했습니다.버전 4의 변경으로 인해 문제가 발생한 것 같습니다.
npm install crypto-js@3.1.9-1
여기 repo 발행물에 설명되어 있습니다.
내 오류
에는 의경더우나더.import { get } from "express/lib/response"
vs-code에 의해 되는 범인입니다.그래서 그것을 제거한 후에 저는 제 문제를 해결했습니다.
aws-sign2
입니다. 패키지 JS 파일)crypto
입니다.JS 모듈), 하지만 당신은 웹 애플리케이션을 다루고 있는 것처럼 보입니다.그것은 말이 됩니다.crypto
모듈은 해당 환경에서 사용할 수 없습니다.
서버 측에서 해야 할 일을 완료할 수 있을까요?그렇지 않으면 다른 패키지를 찾아야 할 수도 있습니다.
라라벨 관성 JS 프로젝트에서 제 솔루션은 다음과 같습니다.
1 - 패키지에 종속성을 추가합니다.제이손
"dependencies": {
"crypto-browserify": "3.12.0",
"crypto-random-string": "^3.3.0",
"stream": "^0.0.2"
}
2-Webpack.config.js:
const path = require('path');
module.exports = {
resolve: {
alias: {
'@': path.resolve('resources/js'),
},
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream'),
},
},
};
3-설치, 빌드 및 실행:
npm install && npm run watch
다음 단계를 사용하여 문제를 해결했습니다.
아래를 tsconfig.json에 추가하여 암호화 경고를 확인합니다.
"paths": {
"crypto": [
"node_modules/crypto-js"
]
},
그리고 아래에 각진.json에 추가합니다.
"options": {
"allowedCommonJsDependencies": [
"crypto-js"
],
...
}
crypto는 Node.js 모듈이므로 Angular에서 작동하지 않습니다.다른 방법이 있을 수도 있고 Node.js를 Angular와 함께 사용할 수도 있습니다.암호화 모듈은 Node.js에서 작동합니다.
직접 가져오기를 사용하면 ES6 환경에서 작동하지 않을 수 있습니다.
도움이 될 수도 있습니다.
$ npm i crypto-js@latest
버전 4를 4를 참조하십시오.
import AES from 'crypto-js/aes';
import Utf8 from 'crypto-js/enc-utf8';
import { secretKey } from './environments/environment';
/** Encryption */
const data = {key: 'Test Value'};
const ciphertext = AES.encrypt(JSON.stringify(data), secretKey).toString();
console.log('Encrypted Data', ciphertext);
/** Decryption */
const bytes = AES.decrypt(ciphertext, secretKey);
const decryptedData = JSON.parse(bytes.toString(Utf8));
console.log('Decrypted Data', decryptedData);
https://github.com/brix/crypto-js/issues/168#issuecomment-785617218
#Laravel 프레임워크를 Laravel Mix와 함께 사용하는 경우 이는 더 많은 속임수가 될 것입니다.저는 이 NPM 악몽에 몇 시간을 소비했고 확실한 해결책을 찾았습니다.
웹팩.mix.js에서 '댓글'을 찾을 수 있습니다.
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
이제 댓글 바로 아래에 다음 행을 추가합니다.
mix.webpackConfig(webpack => {
return {
plugins: [
new webpack.LoaderOptionsPlugin({
exports: {
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
}
}
}
})
]
};
});
이제 webpack.config.js ;) 또한 패키지 내에서 편집할 때와 마찬가지로 Laravel Mix를 사용할 수 있습니다.json 제거:
--no-progress --hide-modules
웹 팩 > = 5에는 더 이상 사용할 수 없습니다.맛있게 드세요!
깊이 연구한 결과 솔루션이 매우 간단하다는 것을 알게 되었습니다. 가져오기 *를 'crypto-js'의 CryptoJS로 바꾸고 var CryptoJ를 선언합니다.S;
배열에 리터럴 "crypto-js"가 있는 allowed CommonJsDependencies 옵션을 추가합니다. 이 옵션은 fileangular.json:
"architect":
"build": {
"options": {
"allowedCommonJsDependencies": [
"crypto-js"
]
},
}
}
그러면 Angular 11에서 테스트한 모든 경고가 비활성화됩니다.
문제는 동일한 코드를 사용하여 노드와 웹에 빌드하려고 했지만 WebSocket 종속성을 가져오는 동안 웹에 빌드할 수 없다는 것입니다. 이 경우 ws
따라서 해결책은 포장지를 사용하는 것입니다.
포장지 설치, ws용으로 만들어졌기 때문에 동형-ws를 사용할 것입니다.
npm i --save isomorphic-ws
제다한을 합니다.const WebSocket = require('ws')
다음으로 대체:
const WebSocket = require('isomorphic-ws')
저는 결국에 들어갔습니다.
node_sys/sys-sys/config/webpack.config.js
추가:
fallback: {
// Here paste
crypto: require.resolve("crypto-browserify"),
https: require.resolve("https-browserify"),
http: require.resolve("stream-http"),
url : require.resolve("url")
}
그리고 이제 제 반응 앱은 오류가 있지만 의존성 문제가 없는 상태로 빌드됩니다.제가 건물을 지을 때 이것을 업데이트하겠습니다.
더하다
npm install crypto-js
또는 프로젝트 필요에 따라 특정 버전을 추가합니다.
npm install crypto-js@4.0.0
또한 "관리자 권한으로 실행" 창에서 위의 명령을 실행하거나 Linux에서 sudo를 사용합니다.
이미 많은 답이 있지만 여전히 작동하지 않습니다.이 경우 경고 메시지가 표시됩니다.
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }' - install 'crypto-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "crypto": false }
@httpsii의 의견은 제가 이 문제를 해결하는 데 도움이 되었습니다.
이제 "crypto-es"라는 ES 모듈 버전이 있습니다.이 경고를 지웁니다.npmjs.com/package/crypto-es
이 후에 가져왔습니다.cryptoES
import CryptoES from 'crypto-es';
의 기존 가져오기 제거cryptoJs
컴파일과 Voila를 다시 시작합니다.경고 메시지가 사라졌습니다.
위의 많은 솔루션을 시도했지만 마지막으로 효과가 있었던 것은 crypto-es 패키지를 다운로드하고 다음과 같이 추가한 것입니다."type":"module"
패키지로.json.
https://www.npmjs.com/package/crypto-es
나도 같은 문제에 직면했어요, 그냥 도망가세요.node patch.js
그리고 그것은 성공하였다.문제는 브라우저가 브라우저에서 서버 파일을 실행하는 것을 허용하지 않는다는 것입니다.이 중 일부가 필요할 경우, 사용할 수 있습니다.node patch.js
브라우저에서 서버 파일을 실행하지 않으려면 위에서 언급한 솔루션을 @R로 적용하면 됩니다.리차드.누군가에게 도움이 될 수도 있습니다.
저의 경우, R이 설명한 솔루션입니다.리차드는 작동하지 않습니다.하지만, 이 문제를 따라 여러 스레드를 수행한 후, 저는 마침내 경고 메시지에 제공된 권장 사항을 어디에 삽입해야 하는지 이해하고 이 경고를 해결했습니다.
WARNING in ./node_modules/bcryptjs/dist/bcrypt.js 64:13-45
Module not found: Error: Can't resolve 'crypto' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\bcryptjs\dist'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
**If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }**
많은 기여자들과 달리, 저는 크립토 브라우저화가 필요하지 않기 때문에(*) 설치를 원하지 않았고, {"crypto": false} 폴백을 추가하기로 선택했습니다.하지만 저는 이 폴백을 어디에 추가해야 할지 몰랐습니다. 여러 스레드를 읽은 후 node_modules/react_scripts/config 디렉토리에 있는 webpack.config.js 파일에 있는 것을 발견했습니다.이 폴백을 추가하면 아무런 경고 없이 컴파일이 성공합니다.
(*) PS: 이전에 다음과 같은 폴백 {"crypto": require.resolve("crypto-browserify")}을(를) 추가하려고 했지만 7개의 오류가 발생하여 다른 모듈이 필요했습니다.
Failed to compile.
Module not found: Error: Can't resolve 'stream' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\cipher-base'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/cipher-base/index.js 2:16-43
Module not found: Error: Can't resolve 'stream' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\cipher-base'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
ERROR in ./node_modules/readable-stream/lib/_stream_readable.js 43:13-37
Module not found: Error: Can't resolve 'buffer' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\readable-stream\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/readable-stream/lib/_stream_writable.js 65:13-37
Module not found: Error: Can't resolve 'buffer' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\readable-stream\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/readable-stream/lib/internal/streams/buffer_list.js 63:15-32
Module not found: Error: Can't resolve 'buffer' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\readable-stream\lib\internal\streams'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/ripemd160/index.js 3:13-37
Module not found: Error: Can't resolve 'buffer' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\ripemd160'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/safe-buffer/index.js 3:13-30
Module not found: Error: Can't resolve 'buffer' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\safe-buffer'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
ERROR in ./node_modules/safer-buffer/safer.js 5:13-30
Module not found: Error: Can't resolve 'buffer' in 'C:\PC\Documents\3 - Projet MAKAO\dev\RepoAlecol\node_modules\safer-buffer'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "buffer": false }
webpack compiled with 7 errors
리액트에서 이 문제가 있었습니다.Create-React-App(페이스북)을 사용한 JS
솔루션:
먼저 필요한 패키지 "crypto-browserify"를 설치합니다.
create-react-app을 사용하여 reactjs의 webpack.config.js를 수정합니다. 이 파일은 내부에 있습니다.
node_sys/sys-sys/config/webpack.config.js
- module.exports를 검색하면 이 함수 안에 다음과 같은 반환이 있습니다.
module.exports = function (webpackEnv) {
...
return {
...
resolve: {
...
fallback: {
// Here paste
crypto: require.resolve("crypto-browserify"),
}
}
}
}
참고: 단계가 동일한 "스트림-브라우저화" 방법으로 다른 패키지가 필요할 수 있습니다.이 솔루션은 작동하지만 웹 팩 프로젝트가 시작되면 경고가 표시됩니다.
PD: 저는 영어를 모국어로 하는 사람은 아니지만, 저를 이해하기를 바랍니다.
언급URL : https://stackoverflow.com/questions/54162297/module-not-found-error-cant-resolve-crypto
'prosource' 카테고리의 다른 글
필드의 기존 값에 접두사를 추가하는 SQL 쿼리 (0) | 2023.08.11 |
---|---|
Oracle 구문 - 기존 구문과 새 구문 중 하나를 선택해야 합니까? (0) | 2023.08.11 |
Spring 데이터 JPA 및 최대 절전 모드 분리 엔티티가 Multi-to-Many 관계를 유지하도록 전달되었습니다. (0) | 2023.08.11 |
Powershell에서 유형 [System]을(를) 찾을 수 없습니다.창문들.Forms.KeyEventHandler] (0) | 2023.08.11 |
CakePHP - 마지막 쿼리 실행 가져오기 (0) | 2023.08.06 |