私は現在、自分の webpack アプリケーションで sass を動作させようとしています。style-loader
&の構成に成功しましたcss-loader
。ただし、実装しようとするsass-loader
と、次のエラーが表示されます。
bundle.js:598 Uncaught Error: Cannot find module "!!./../../css-loader/index.js!./../../sass-loader/index.js!./index.js?http:/localhost:8000"
style-loader
&をインストールする手順を説明しますcss-loader
。
- ラン
npm install style-loader css-loader --save-dev
ローダーを webpack.config に追加しました:
module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'react-hot!babel' }, { test: /\.css$/, exclude: /node_modules/, loader: "style-loader!css-loader", } ] }
css フォルダーを作成し、そこに配置します
myStyle.css
- スタイルシートを反応コンポーネントにインポートしました
require(../../css/myStyle.css
これは機能し、問題はありませんでした。この後、追加しようとしましたsass-loader
。私が行った手順は、最初の手順と非常に似ていました。
- ラン
npm install sass-loader node-sass --save-dev
webpack.config にローダーを追加しました
module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'react-hot!babel' }, { test: /\.css$/, exclude: /node_modules/, loader: "style-loader!css-loader", }, { text: /\.scss$/, exlude: /node_modules/, loader: "style-loader!css-loader!sass-loader" } ] }
に変更
myStyle.css
しmyStyle.scss
ます。- スタイルシートを反応コンポーネントにインポートしました
require('../../myStyle.scss')
この後、上記の DOM に貼り付けられたエラーを受け取ります。コンソールが私にbarfsするエラーは次のとおりです。
[1] (webpack)-dev-server/client?http://localhost:8000 1.01 kB {0} [built] [1 error]
[3] ./~/style-loader/addStyles.js 7.15 kB {0} [built]
[4] (webpack)/hot/only-dev-server.js 981 bytes {0} [built] [1 error]
[6] ./src/index.jsx 2.42 kB {0} [built] [1 error]
[7] (webpack)/buildin/module.js 954 bytes {0} [built] [1 error]
[9] ./~/react-hot-loader/~/react-hot-api/modules/index.js 993 bytes {0} [built] [1 error]
[11] ./~/react-hot-loader/RootInstanceProvider.js 975 bytes {0} [built] [1 error]
[13] ./~/react/lib/ReactMount.js 966 bytes {0} [built] [1 error]
[15] ./~/react/react.js 930 bytes {0} [built] [1 error]
[18] ./~/react-hot-loader/makeExportsHot.js 957 bytes {0} [built] [1 error]
ERROR in ./~/css-loader!./~/sass-loader!./src/index.jsx
Module build failed:
import React from 'react';
^
Invalid CSS after "i": expected 1 selector or at-rule, was "import React from '"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/src/index.jsx (line 1, column 1)
@ ./src/index.jsx 8:14-115 17:2-21:4 18:20-121
ERROR in ./~/css-loader!./~/sass-loader!(webpack)-dev-server/client? http:/localhost:8000
Module build failed:
var url = require('url');
^
Invalid CSS after "v": expected 1 selector or at-rule, was "var url = require('"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/webpack-dev-server/client/index.js (line 1, column 1)
@ (webpack)-dev-server/client?http://localhost:8000 4:14-115 13:2-17:4 14:20-121
ERROR in ./~/css-loader!./~/sass-loader!(webpack)/hot/only-dev-server.js
Module build failed:
var lastData;
^
Property "var" must be followed by a ':'
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/webpack/hot/only-dev-server.js (line 7, column 2)
@ (webpack)/hot/only-dev-server.js 4:14-104 13:2-17:4 14:20-110
ERROR in ./~/css-loader!./~/sass-loader!./~/react-hot- loader/RootInstanceProvider.js
Module build failed:
'use strict';
^
Invalid CSS after "'": expected 1 selector or at-rule, was "'use strict';"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/react-hot-loader/RootInstanceProvider.js (line 1, column 1)
@ ./~/react-hot-loader/RootInstanceProvider.js 4:14-103 13:2-17:4 14:20-109
ERROR in ./~/css-loader!./~/sass-loader!(webpack)/buildin/module.js
Module build failed:
module.exports = function(module) {
^
Invalid CSS after "module.exports": expected "{", was "= function(module) "
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/webpack/buildin/module.js (line 1, column 15)
@ (webpack)/buildin/module.js 4:14-95 13:2-17:4 14:20-101
ERROR in ./~/css-loader!./~/sass-loader!./~/react-hot-loader/makeExportsHot.js
Module build failed:
'use strict';
^
Invalid CSS after "'": expected 1 selector or at-rule, was "'use strict';"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/react-hot-loader/makeExportsHot.js (line 1, column 1)
@ ./~/react-hot-loader/makeExportsHot.js 4:14-97 13:2-17:4 14:20-103
ERROR in ./~/css-loader!./~/sass-loader!./~/react/lib/ReactMount.js
Module build failed:
*/
^
Invalid CSS after " */": expected 1 selector or at-rule, was "'use strict';"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/react/lib/ReactMount.js (line 10, column 4)
@ ./~/react/lib/ReactMount.js 4:14-99 13:2-17:4 14:20-105
ERROR in ./~/css-loader!./~/sass-loader!./~/react-hot-loader/~/react-hot-api/modules/index.js
Module build failed:
'use strict';
^
Invalid CSS after "'": expected 1 selector or at-rule, was "'use strict';"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/react-hot-loader/node_modules/react-hot-api/modules/index.js (line 1, column 1)
@ ./~/react-hot-loader/~/react-hot-api/modules/index.js 4:14-106 13:2-17:4 14:20-112
ERROR in ./~/css-loader!./~/sass-loader!./~/react/react.js
Module build failed:
'use strict';
^
Invalid CSS after "'": expected 1 selector or at-rule, was "'use strict';"
in /Users/tsiebenhaar/Sites/extendedFamily-frontend/node_modules/react/react.js (line 1, column 1)
@ ./~/react/react.js 4:14-88 13:2-17:4 14:20-94
webpack: bundle is now VALID.
提案や助けをいただければ幸いです。今のところ私は寝て、明日の朝に戻ってきます。コーディングをお楽しみください。おやすみなさい。