2017-06-28 13 views
0

ReduxとExpressでNodejを使用するように教えています。私の見解にはタグがあります。それだけです。非常に、非常に基本的。コンソールにエラーが表示され、わかりません。Node.js/Redux/Expressエラー

Uncaught ReferenceError: process is not defined 
at Object.<anonymous> (bundle.js:548) 
at __webpack_require__ (bundle.js:20) 
at Object.defineProperty.value (bundle.js:492) 
at __webpack_require__ (bundle.js:20) 
at Object.<anonymous> (bundle.js:482) 
at __webpack_require__ (bundle.js:20) 
at __webpack_exports__.b (bundle.js:63) 
at bundle.js:66 

これは何を意味するのでしょうか?ここで

は私のserver.jsファイルです:

"use strict" 
var express = require('express'); 
var app = express(); 
var path = require('path'); 

// MIDDLEWARE TO DEFINE FOLDER FOR STATIC FILES 
app.use(express.static('public')) 

app.get('/', function(req, res){ 
    res.sendFile(path.resolve(__dirname, 'public', 'index.html')) 
}) 

app.listen(3000, function(){ 
    console.log('app is listening'); 
}) 

ここに私のapp.jsファイルされる:

"use strict" 

import {createStore} from 'redux' 


// STEP 3 define reducers 

const reducer = function(state=0, action){ 
    switch(action.type){ 
     case "INCREMENT": 
     return state + action.payload; 
     break; 
    } 
    return state 
} 


// STEP 1 create the store 
const store = createStore(reducer); 

store.subscribe(function(){ 
    console.log('current state is: ' + store.getState()); 
}) 

// STEP 2 create and dispatch actions 
store.dispatch({type: "INCREMENT", payload: 1 }) 

ここでは私のwebpack.config.jsファイルです:

var path = require('path'); 

const webpack = require('webpack'); 

module.exports = { 
    entry: ['./src/app.js'], 
    output: { 
     filename: 'bundle.js', 
     path: path.resolve(__dirname, 'public') 
    }, 
    target: 'node', 
    watch: true, 
    module: { 
     loaders: [ 
     { 
      test: /\.js$/, 
      exclude: /node_modules/, 
      loader: 'babel-loader', 
      query: { 
      presets: ['react', 'es2015', 'stage-1'] 
      } 
     } 
     ] 
    } 
} 
+0

どのようにアプリケーションを実行していますか? –

+0

ノードserver.js次にwebpack –

+0

を使用しています。私は通常、Railsを使用します。 –

答えて

0

このコードをwebpack.configのプラグイン部分に追加してみてください

new webpack.DefinePlugin({ 
     "process.env": { 
     NODE_ENV: JSON.stringify("production") //or "development" 
     } 
    }); 

これがあなたの問題である理由については、以下で読むことができます。基本的には、webpackにNODE_ENV変数を与える必要があります。

https://github.com/facebook/react/blob/f7850dd3d78d313a9e7774870e85c32719fbe233/docs/docs/getting-started.md

関連する問題