저는 Mobx와 함께 React와 Mobx를 사용하는 프로젝트를 가지고 있습니다.mobx 및 mobx-react와 함께 Webpack 빌드 문제가 발생했습니다.
내 프로젝트는 로컬에서 완벽하게 실행됩니다. webpack -p
사용하여 구축 그러나, 나는 콘솔에서 다음과 같은 오류와 함께 빈 화면을 얻을 :
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를 사용하여 하나 개의 파일이 있습니다 : 여기
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)
나의 웹팩 설정입니다 프로젝트, 그리고 그 오류가 참조하는 파일은 Category.jsx
입니다.
Category.jsx
샘플 :
import { observer } from 'mobx-react'
import { observable } from 'mobx'
...
@observer class Category extends React.Component {
@observable showingSmallMenu = false
...
}
나는 로컬이 모든 일이 완벽하게 잘 말하는 것처럼.
여기에서 문제가 될 수있는 것은 무엇입니까?
'mobx'를'dependencies' 대신'devDependencies'로 설치 했습니까? –