javascript - React from NPM cannot be used on the client because 'development' is not defined. The bundle was generated from Webpack -


i'm creating react node.js app , i'm trying generate webpack bundle containing react source code loaded npm.

however, seems react code npm cannot used directly in client. triggers error:

uncaught referenceerror: development not defined 

the code triggers exception react code:

sample

is there can make work?

edit

this webpack.config.js:

import _ 'lodash'; import webpack 'webpack'; import yargs 'yargs'; import extracttextplugin 'extract-text-webpack-plugin';  export default {     entry: {         bundle: './src/client.js'     },      output: {         filename: '[name].js',         path: './dist/assets',         publicpath: '/assets/'     },      externals: undefined,      resolve: {         extensions: ['', '.js', '.json']     },      module: {         loaders: [             {test: /\.js/, loader: 'babel?optional=es7.objectrestspread!client', exclude: /node_modules/ },             {test: /\.css/, loader: extracttextplugin.extract("style-loader", "css-loader")},             {test: /\.less$/, loader:  extracttextplugin.extract("style-loader", "css-loader!less-loader")},             {test: /\.json$/, loader: 'json'},             {test: /\.jpe?g$|\.gif$|\.png$/, loader: 'file?name=[name].[ext]'},             {test: /\.eot$|\.ttf$|\.svg$|\.woff2?$/, loader: 'file?name=[name].[ext]'}         ]     },      plugins: [         new webpack.defineplugin({             'process.env': {                 'node_env': 'development'             },             'development': true         }),         new extracttextplugin('[name].css')     ] }; 

my client.js file contains line (for purpose of debugging issue):

import react 'react'; 

and here resulting bundle

any values passed webpack.defineplugin strings treated code fragments—that say, using

new webpack.defineplugin({   env: "development" }); 

with code

console.log(env); 

results in

console.log(development); 

instead, want

new webpack.defineplugin({   env: "\"development\"" }); 

which result in

console.log("development"); 

to fix issue, change plugins to

plugins: [     new webpack.defineplugin({         'process.env': {             'node_env': "'development'"         }     }),     new extracttextplugin('[name].css') ] 

i allow webpack read process.env.node_env react minifies when run webpack node_env=production:

new webpack.defineplugin({   "process.env": { node_env: json.stringify(process.env.node_env || "development") } }) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -