現状
ReactJSのアプリケーションを作っています。そこで
Uncaught SyntaxError: Unexpected token <
というエラーが起き続けている状態です。homeのページでも詳細のページでも起きてしまいます。
またhomeのページから、詳細のページにいくと、上記のエラーに加えて
bundle.js:1 Uncaught TypeError: Cannot read property 'pathname' of undefined
というエラーメッセージが表示され、ブランクページになります。(homeのページは問題なく表示されています)
ネットワークのタブを見てみると、bundle.js
は404
のステータスになっており、style.css
はキャンセル
されてしまっています。
なぜ詳細ページでのみこのようなエラーができるのかわからず、どこに問題があるのかも不明な状態です。。
コード
index.html
では以下のようにpathを指定しており、実際にバンドルしたファイルもフォルダ内にあります。
<script type="text/javascript" src="./dist/bundle.js"></script>
<link rel="stylesheet" href="./dist/style.css">
webpack.config.js
は以下のように設定しております。
js
1const path = require('path'); 2const ExtractTextPlugin = require('extract-text-webpack-plugin'); 3 4module.exports = [ 5 { 6 mode: 'production', 7 entry: './src/index.js', 8 watch: true, 9 output: { 10 path: path.resolve(__dirname, 'dist'), 11 filename: 'bundle.js' 12 }, 13 module: { 14 rules: [ 15 { 16 exclude: /node_modules/, 17 loader: 'babel-loader', 18 query: { 19 compact: true, 20 presets: ['react', 'es2015', 'stage-1', 'flow'] 21 } 22 }, { 23 test: /.svg$/, 24 loader: 'babel-loader!svg-react-loader' 25 }, { 26 test: /.(jpg|png)$/, 27 loader: 'url-loader' 28 }, { 29 test: /.json$/, 30 loader: 'json-loader' 31 }, { 32 test: /.css$/, 33 loader: 'style-loader!css-loader?modules' 34 }, { 35 test: /.scss$/, 36 loader: 'sass-loader!css-loader' 37 } 38 39 ] 40 }, 41 resolve: { 42 extensions: ['*', '.js', '.jsx', '.json'] 43 }, 44 devServer: { 45 compress: true, 46 historyApiFallback: true, 47 port: 8080 48 } 49 }, { 50 mode: 'production', 51 entry: './style/style.scss', 52 watch: true, 53 output: { 54 path: path.resolve(__dirname, "dist"), 55 filename: 'style.css' 56 }, 57 module: { 58 rules: [ 59 { 60 test: /.scss$/, 61 use: ExtractTextPlugin.extract({ 62 use: [ 63 { 64 loader: 'css-loader' 65 }, { 66 loader: 'sass-loader' 67 } 68 ], 69 fallback: 'style-loader' 70 }) 71 } 72 ] 73 }, 74 plugins: [new ExtractTextPlugin('style.css')] 75 } 76]; 77
もし、原因がわかる方がいましたら教えていただけるととても助かります。m(_ _)m
追記
index.htmlのpathの指定が間違っていたようで、404のエラーは直りました!が、まだUnexpected token <
と'pathname' of undefined
のエラーが出ています。。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/17 08:42
2018/05/17 08:47
2018/05/18 02:42
2018/05/18 03:20
2018/05/18 04:14