お世話になっております。
現在React + reduxで開発を行っており、 reduxの内容を永続的に記録するためredux-localstorageを利用したいと考えております。
そこでredux-localstorageを使用する上でおそらくadapterが必要だと思うのですが、
tsx
1import adapter from 'redux-localstorage/lib/adapters/localStorage';
上記のインポートにwebpackがエラーを出力します。
ERROR in ./src/index.tsx Module not found: Error: Can't resolve 'redux-localstorage/lib/adapters/localStorage' in '/myProject/src' @ ./src/index.tsx 7:0-67 9:46-53
ちなみにvimにTSの言語サーバーを利用して使っているのですが、 そちらはエラーを表示せず、 インポートを無事解決しているようでした。
色々と調べて(参考: IMPORT PARTS OF NODE PACKAGES WITH SLASH)、 インポートの書き方自体が間違っている感じはなさそうです。また、 'redux-localstorage/lib/adapters/localStorage'もQiitaの記事などで書いている方が多いので、 合っていると思います。
そこでWebpackの設定が怪しいのではないかと思い2時間ほど調べたのですが、 分かりませんでした。
どなたかご存知の方がいらっしゃいましたらご教授いただけますと幸いです。
よろしくお願いいたします。
webpack.config.js
1const fs = require('fs') 2const fsExtra = require('fs-extra') 3const CopyPlugin = require('copy-webpack-plugin') 4const Dotenv = require('dotenv-webpack') 5 6const production = process.env.NODE_ENV === 'production' 7let plugins = [] 8if (production) { 9 // reset build directory 10 const build = `${__dirname}/build` 11 if (fs.existsSync(build)) { 12 fsExtra.removeSync(build) 13 } 14 fs.mkdirSync(build) 15 16 plugins = [ 17 new CopyPlugin([ 18 { from: `${__dirname}/public`, to: `${__dirname}/build` } 19 ]) 20 ] 21} 22 23plugins.push(new Dotenv({ 24 path: './.env' 25})) 26 27module.exports = { 28 mode: production ? "production" : "development", 29 entry: "./src/index.tsx", 30 output: { 31 filename: "index.js", 32 path: `${__dirname}/${production ? "build" : "public"}`, 33 }, 34 devtool: "source-map", 35 module: { 36 rules: [ 37 { 38 test: /.(ts|tsx)$/, 39 use: "ts-loader", 40 exclude: "/node_modules/", 41 }, 42 { 43 test: /.(css|sass)$/, 44 use: [ 45 "style-loader", 46 "css-loader", 47 "sass-loader" 48 ], 49 exclude: "/node_modules/" 50 }, 51 { 52 test: /.(jpg|png)$/, 53 use: "url-loader", 54 exclude: "/node_modules/" 55 } 56 ] 57 }, 58 resolve: { 59 extensions: [".js", ".ts", ".tsx"], 60 modules: ["node_modules"] 61 }, 62 devServer: { 63 contentBase: `${__dirname}/public`, 64 watchContentBase: true, 65 historyApiFallback: true, 66 disableHostCheck: true 67 }, 68 plugins 69}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。