Giter VIP home page Giter VIP logo

Comments (7)

carloscuatin avatar carloscuatin commented on April 30, 2024 2

not use babel-plugin-react-transform in .babelrc. use config in webpack.config.js
example

module: {
    loaders: [
      {
        test: /\.(js|jsx)$/,
        loader: 'babel',
        include: path.join(__dirname, 'src'),
        query: {
          plugins: [
            ["react-transform", {
              transforms: [{
                transform: "react-transform-hmr",
                imports: ["react"],
                locals: ["module"]
              }, {
                "transform": "react-transform-catch-errors",
                "imports": ["react", "redbox-react"]
              }]
            }]
          ]
        }
      }
    ]
  }

it is support in isomorphic apps (y)

from babel-plugin-react-transform.

olegakbarov avatar olegakbarov commented on April 30, 2024

What are the contents of your .babelrc and npm scripts?

from babel-plugin-react-transform.

Deathsteps avatar Deathsteps commented on April 30, 2024

.babelrc:

{
  "presets": ["react", "es2015"],
  "env": {
    "development": {
      "plugins": [
        ["react-transform", {
          "transforms": [{
            "transform": "react-transform-hmr",
            "imports": ["react"],
            "locals": ["module"]
          }, {
            "transform": "react-transform-catch-errors",
            "imports": ["react", "redbox-react"]
          }]
        }]
      ]
    }
  }
}

npm scripts:

"scripts": {
    "start": "node ./bin/www",
    "test": "mocha"
  }

I just set up an express server with a webpack-dev-middleware in the start script.

I built the configuration based on gaearon's react-transform-boilerplate.

from babel-plugin-react-transform.

Deathsteps avatar Deathsteps commented on April 30, 2024

@carloscuatin you are brilliant! It works.

from babel-plugin-react-transform.

Dakuan avatar Dakuan commented on April 30, 2024

@carloscuatin thanks! got me up and running too 👍

from babel-plugin-react-transform.

gaearon avatar gaearon commented on April 30, 2024

Seems like, babel cant figure out whether the file is required in the server side or not. So it apply the react-transform-hmr on every jsx file.

Babel only checks the NODE_ENV. Look at your .babelrc:

{
  "presets": ["react", "es2015"],
  "env": {
    "development": {
      ...

This means the plugin activates when NODE_ENV is equal to development or absent because this is the default.

So the solution is to tell Babel to use another configuration on the server by specifying NODE_ENV.

# any of these will do!

NODE_ENV=production node app.js
NODE_ENV=server node app.js
NODE_ENV=server-development node app.js
NODE_ENV=whatever node app.js

# but not this!
node app.js

We already say this in README but sadly people look over it. :-(

// this plugin will be included only in development mode, e.g.
// if NODE_ENV (or BABEL_ENV) environment variable is not set
// or is equal to "development"

from babel-plugin-react-transform.

webxzy avatar webxzy commented on April 30, 2024

删除(delete) .bablerc => env =>"development": {"presets": ["react-hmre"]}

{
	"presets": ["react","es2015", "stage-0"],
	"plugins": [],
	"env": {}
}

from babel-plugin-react-transform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.