2017-08-03 8 views
0

は、ここで私はこれの近くにコピーされ、別のプロジェクトを持っており、それが正常に動作し、オフの事はある私のWebPACKの設定予期しないトークン。 WebPACKのでの.cssファイルをインポートするとき

module: { 
    loaders: [ 
    { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel?' + JSON.stringify(babelLoaderQuery), 'eslint-loader']}, 
    { test: /\.json$/, loader: 'json-loader' }, 
    { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' }, 
    { test: /\.css$/, loader: 'style!css?importLoaders=1!autoprefixer?browsers=last 2 version!sass' }, 

です。どちらの場合も、私はこのように.cssをインポートします。

import 'react-day-picker/lib/style.css' 

エラー:

[require-hacker] Trying to load "style.css" as a "*.js" 
[1] [piping] can't execute file: /Users/myUser/Projects/fed/bin/server.js 
[1] [piping] error given was: /Users/myUser/Projects/fed/node_modules/react-day-picker/lib/style.css:3 
[1] .DayPicker { 
[1]^
[1] 
[1] SyntaxError: Unexpected token . 
[1]  at createScript (vm.js:74:10) 
[1]  at Object.runInThisContext (vm.js:116:10) 
[1]  at Module._compile (module.js:533:28) 
[1]  at Module._extensions..js (module.js:580:10) 
[1]  at require.extensions.(anonymous function) (/Users/myUser/Projects/fed/node_modules/babel-register/lib/node.js:152:7) 
[1]  at Object._module2.default._extensions.(anonymous function) [as .js] (/Users/myUser/Projects/fed/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:260:68) 
[1]  at Module.load (module.js:503:32) 
[1]  at tryModuleLoad (module.js:466:12) 
[1]  at Module._load (module.js:458:3) 
[1]  at Function.module._load (/Users/myUser/Projects/fed/node_modules/piping/lib/launcher.js:32:16) 
[1] [piping] further repeats of this error will be suppressed... 

答えて

1

ここでの仕事のビットがそれの周りです。

import isBrowser from 'is-in-browser'; 

if (isBrowser) { 
    require ('react-day-picker/lib/style.css') 
} 
+0

を実際に働いていた唯一のブラウザでそれをやって願っています。 – Noah

0

かもしれません:私は過去バベルを取得し、唯一のアプリは、あなたがこのようなあなたのコンポーネントで使用することができ、ブラウザウィンドウで実行されていた場合は、外部スタイルシートをインポートすることで、ブラウザ内のモジュールを使用して私のプロジェクトでこのため

{ test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel?' + JSON.stringify(babelLoaderQuery), 'eslint-loader']}, 

であることがこれだけbablifies .jsxのファイルと除外ノードモジュール、あなたはまたの.jsファイルの設定を追加してから分かるように、ローダが実行されている間ノードモジュールの内部で行かないことに言及する必要がありますあなたのスタックトレース。

何か

よう
{ test: /\.js?$/, exclude: /node_modules/, loaders: ['babel?' + JSON.stringify(babelLoaderQuery), 'eslint-loader']}, 

は、それが役立ちます:)

関連する問題