yarn webpackコマンド実行後に以下のエラーメッセージが出力されます。
# yarn webpack yarn run v1.22.19 $ /usr/local/TEST/frontend/node_modules/.bin/webpack asset bundle.js 2.74 MiB [emitted] (name: main) orphan modules 498 KiB [orphan] 278 modules runtime modules 1.31 KiB 6 modules cacheable modules 2.24 MiB 299 modules ERROR in ./node_modules/follow-redirects/index.js 3:11-26 Module not found: Error: Can't resolve 'http' in '/usr/local/TEST/frontend/node_modules/follow-redirects' Did you mean './http'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too. 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: { "http": require.resolve("stream-http") }' - install 'stream-http' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "http": false } @ ./node_modules/axios/dist/node/axios.cjs 9:24-51 @ ./src/components/pages/Login.tsx 63:30-46 @ ./src/App.tsx 5:14-49 @ ./src/index.tsx 8:12-28 ERROR in ./node_modules/follow-redirects/index.js 4:12-28 Module not found: Error: Can't resolve 'https' in '/usr/local/TEST/frontend/node_modules/follow-redirects' Did you mean './https'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too. 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: { "https": require.resolve("https-browserify") }' - install 'https-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "https": false } @ ./node_modules/axios/dist/node/axios.cjs 9:24-51 @ ./src/components/pages/Login.tsx 63:30-46 @ ./src/App.tsx 5:14-49 @ ./src/index.tsx 8:12-28 ERROR in ./node_modules/zlib/lib/zlib.js 1:0-43 Module not found: Error: Can't resolve './zlib_bindings' in '/usr/local/TEST/frontend/node_modules/zlib/lib' @ ./node_modules/axios/dist/node/axios.cjs 10:13-28 @ ./src/components/pages/Login.tsx 63:30-46 @ ./src/App.tsx 5:14-49 @ ./src/index.tsx 8:12-28 ERROR in ./node_modules/axios/dist/node/axios.cjs 7:13-28 Module not found: Error: Can't resolve 'http' in '/usr/local/TEST/frontend/node_modules/axios/dist/node' 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: { "http": require.resolve("stream-http") }' - install 'stream-http' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "http": false } @ ./src/components/pages/Login.tsx 63:30-46 @ ./src/App.tsx 5:14-49 @ ./src/index.tsx 8:12-28 ERROR in ./node_modules/axios/dist/node/axios.cjs 8:14-30 Module not found: Error: Can't resolve 'https' in '/usr/local/TEST/frontend/node_modules/axios/dist/node' 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: { "https": require.resolve("https-browserify") }' - install 'https-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "https": false } @ ./src/components/pages/Login.tsx 63:30-46 @ ./src/App.tsx 5:14-49 @ ./src/index.tsx 8:12-28 5 errors have detailed information that is not shown. Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it. webpack 5.74.0 compiled with 5 errors in 15654 ms error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
以下のコマンドを実行しましたが、解決しません。
yarn add http https
npm install https-browserify stream-http
解決方法をご存知の方がいればご教示願います…。
package.jsonは以下になります。
{ "name": "frontend", "version": "0.1.0", "private": true, "dependencies": { "@emotion/react": "^11.10.4", "@emotion/styled": "^11.10.4", "@mui/material": "^5.10.10", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "@types/jest": "^27.5.2", "@types/node": "^16.18.0", "@types/react": "^18.0.21", "@types/react-dom": "^18.0.6", "assert": "^2.0.0", "axios": "^1.1.3", "browserify-zlib": "^0.2.0", "http": "^0.0.1-security", "https": "^1.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.4.2", "react-scripts": "5.0.1", "stream": "^0.0.2", "stream-browserify": "^3.0.0", "typescript": "^4.8.4", "url": "^0.11.0", "web-vitals": "^2.1.4", "zlib": "^1.0.5" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "https-browserify": "^1.0.0", "react-app-rewired": "^2.2.1", "stream-http": "^3.2.0", "ts-loader": "^9.4.1", "webpack": "^5.74.0", "webpack-cli": "^4.10.0", "webpack-dev-server": "^4.11.1" } }
tsconfig.jsonは以下になります。
{ "compilerOptions": { "target": "es5", // コンパイル後のJavaScriptのバージョンの指定 "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, // CommonJS形式のモジュールを扱えるようにする "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "commonjs", // コンパイル後のモジュールパターンの指定 "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "jsx": "react-jsx" }, "include": [ "src" ] }
webpack.config.jsは以下になります。
// パス操作を行うためのpathモジュールをインポート // Node.jsに標準搭載されている const path = require('path'); // モジュールの作成 module.exports = { // モジュールバンドルを行うファイルの指定 mode: 'development', entry: './src/index.tsx', //buildするファイル output: { filename: 'bundle.js', //build後のファイル名 path: path.join(__dirname, '../backend/static/js') //buildファイルが作成される場所 }, // モジュールに適用するルールの設定 module: { // 拡張子が.tsで終わるファイルに対して、ts-loaderを適用している rules: [{ test: /\.tsx?$/, loader: 'ts-loader', exclude: /node_modules/, }, ], }, // モジュール解決方法の設定 resolve: { // モジュールとして扱いたいファイルの拡張子を省略する。 // import { hoge } from 'Hoge'; とあった場合 Hoge.ts を読み込む。なければ Hoge.tsx を読み込む。 extensions: ['.ts', '.tsx', '.js', '.jsx'], } };
回答1件
あなたの回答
tips
プレビュー