2017-04-10 19 views
0

私はMobxを使ってReactとMobxを使用するプロジェクトを持っています。mobxとmobx-reactでWebpackビルドの問題

私のプロジェクトはローカルで完全に正常に動作します。 webpack -pを使用して構築されたときしかし、私は、コンソールで次のエラーで、空白の画面が出ます:ここで

webpack:///./~/mobx-react/index.js?:3 Uncaught Error: Cannot find module "mobx" 
    at webpackMissingModule (webpack:///./~/mobx-react/index.js?:3) 
    at webpackUniversalModuleDefinition (webpack:///./~/mobx-react/index.js?:3) 
    at eval (webpack:///./~/mobx-react/index.js?:10) 
    at Object.<anonymous> (bundle.js:18) 
    at n (bundle.js:1) 
    at eval (webpack:///./src/components/Category.jsx?:35) 
    at Object.<anonymous> (bundle.js:27) 
    at n (bundle.js:1) 
    at eval (webpack:///./src/components/CategoryNavsDates.jsx?:15) 
    at Object.<anonymous> (bundle.js:14) 

は私のWebPACKの設定です:

var path = require('path'); 
var webpack = require('webpack'); 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 
const autoprefixer = require('autoprefixer') 
var CopyWebpackPlugin = require('copy-webpack-plugin'); 

var BUILD_DIR = path.resolve(__dirname, 'build/'); 
var SOURCE_DIR = path.resolve(__dirname, 'src/'); 

module.exports = { 
    devtool: 'eval', 
    entry: SOURCE_DIR + '/index.jsx', 
    output: { 
    path: BUILD_DIR, 
    filename: 'bundle.js' 
    }, 

    module: { 
    rules: [ 
     { 
     test: /\.(js|jsx)$/, 
     exclude: /node_modules/, 
     loader: 'babel-loader', 
     query: { 
      cacheDirectory: true, 
      plugins: ['transform-decorators-legacy'], 
      presets: ['es2015', 'stage-0', 'react'] 
     } 
     }, 
     { 
     test: /\.css$/, 
     use: [ 
      'style-loader', 
      { loader: 'css-loader', options: { modules: true, importLoaders: 1, localIdentName: "[name]__[local]___[hash:base64:3] "} }, 
      { loader: 'postcss-loader', options: {} }, 
     ] 
     }, 
    ], 
    }, 
    resolve: { 
    extensions: ['.js', '.jsx'], 
    }, 
    plugins: [ 
    new webpack.LoaderOptionsPlugin({ 
     options: { 
     postcss: function() { 
      return [ 
      require('postcss-import'), 
      require('postcss-cssnext'), 
      ]; 
     }, 
     } 
    }), 
    new CopyWebpackPlugin([{ from: 'index.html', to: '' },]) 
    ], 
    devServer: { 
    historyApiFallback: true 
    }, 
}; 

私の全体でMobxを使用してファイルは1つだけありますプロジェクト、それはエラーが参照するファイル、Category.jsxです。

Category.jsxサンプル:

import { observer } from 'mobx-react' 
import { observable } from 'mobx' 
... 
@observer class Category extends React.Component { 
    @observable showingSmallMenu = false 
    ... 
} 

私はこれを言うように、すべてがローカルに完全に正常に動作します。

ここで問題が発生する可能性がありますか?

+0

'mobx'を' dependencies'ではなく 'devDependencies'としてインストールしましたか?それはむしろ 'mobx-react'より' index.js'から来ているこの時間を除いて –

答えて

1

mobxmobx-reactの前にインポートすると違いがありますか?

+0

同じエラーを示し、: '(真) \t \t module.exportsは場合=工場(__ webpack_requireの__(2)、__webpack_require __((! ( "モジュール\" mobx \ ""); e.code = 'MODULE_NOT_FOUND' ;; throw e;}()))、__webpack_require __(76)); \t else if(typeof define === 'function' && define.amd) \t \t define(["react"、 "mobx"、 "react-dom"]、factory); ... ' – alanbuchanan

+0

index.jsはどのように見えますか? – mweststrate

+0

ここはhttps://gist.github.com/alanbuchanan/dee5be42509ad74ead4f7c9702e52417です – alanbuchanan

関連する問題