TypeScriptで書かれたファイルをWebpackでバンドルして1つのファイルにまとめようとしていたところ、バンドル後のファイルを実行する際に以下のようにエラーが出て実行ができないので解決方法を教えていただけると幸いです。
bash
1Error: Cannot find module '**/basblu/node_modules/os-locale/index.js' 2 at webpackEmptyContext (**/basblu/lib/bundle.js:67218:10) 3 at ./node_modules/require-uncached/index.js.module.exports (**/basblu/lib/bundle.js:67264:78) 4 at Object../node_modules/cheerio-httpcli/lib/client.js (**/basblu/lib/bundle.js:15494:23) 5 at __webpack_require__ (**/basblu/lib/bundle.js:20:30) 6 at Object../node_modules/cheerio-httpcli/lib/core.js (**/basblu/lib/bundle.js:16104:21) 7 at __webpack_require__ (**/basblu/lib/bundle.js:20:30) 8 at Object../node_modules/cheerio-httpcli/index.js (**/basblu/lib/bundle.js:14206:18) 9 at __webpack_require__ (**/basblu/lib/bundle.js:20:30) 10 at Object../src/index.ts (**/basblu/lib/bundle.js:84295:16) 11 at __webpack_require__ (**/basblu/lib/bundle.js:20:30) 12npm ERR! code ELIFECYCLE 13npm ERR! errno 1 14npm ERR! allscraping@1.0.0 run: `npm run build&& node ./lib/bundle.js` 15npm ERR! Exit status 1 16npm ERR! 17npm ERR! Failed at the allscraping@1.0.0 run script. 18npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 19 20npm ERR! A complete log of this run can be found in: 21npm ERR! /Users/morita1/.npm/_logs/2019-03-02T01_26_42_198Z-debug.log
(※フォルダの名前は**に変更しています。)
webpach.config.js
js
1const path = require('path') 2 3module.exports = { 4 mode: 'development', 5 entry: './src/index.ts', 6 target: 'node', 7 devtool: 'inline-source-map', 8 module: { 9 rules: [ 10 // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'. 11 { test: /.tsx?$/, loader: 'awesome-typescript-loader' }, 12 13 // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'. 14 { enforce: 'pre', test: /.js$/, loader: 'source-map-loader' } 15 ] 16 }, 17 resolve: { 18 extensions: ['.tsx', '.ts', '.js'], 19 modules: ['node_modules'], 20 alias: { 21 'os-locale': './node_modules/os-locale' 22 } 23 }, 24 25 output: { 26 filename: 'bundle.js', 27 path: path.resolve(__dirname, 'lib'), 28 publicPath: './' 29 }, 30 node: { 31 __dirname: false, 32 'os-locale': 'mock' 33 } 34}
試したこと
- webpack.config.jsのnodeにos-localeをついか
- os-localeのインストール
- aliasにos-locale
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。