Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@babel/register does not work with babel-preset-react-app #9920

Closed
JennerChen opened this issue Apr 29, 2019 · 3 comments
Closed

@babel/register does not work with babel-preset-react-app #9920

JennerChen opened this issue Apr 29, 2019 · 3 comments
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@JennerChen
Copy link

Bug Report

Current Behavior
I am trying using create-react-app to do some ssr with express. create-react-app use babel-preset-react-app preset. babel-preset-react-app contains @babel/preset-env, After I use @babel/preset-env instead, it works.
I want to know why I can't direct use babel-preset-react-app ?
Input Code

require('@babel/register')({
  ignore: [/(node_modules)/],
  presets: [
    "babel-preset-react-app"
  ]
});
require('./app');
// app.js
import path from 'path' 
/Users/zhangqing/Documents/web/mini-react-ssr-demo/server/app.js:1
(function (exports, require, module, __filename, __dirname) { import path from 'path'; //import fs from 'fs'
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Module._compile (/Users/zhangqing/Documents/web/mini-react-ssr-demo/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (module.js:664:10)
    at Object.newLoader [as .js] (/Users/zhangqing/Documents/web/mini-react-ssr-demo/node_modules/pirates/lib/index.js:104:7)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mini-react-ssr-demo@0.1.0 ssr: `NODE_ENV=production node ./server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mini-react-ssr-demo@0.1.0 ssr script.

Expected behavior/code
A clear and concise description of what you expected to happen (or code).

Environment

  • Node/npm version: 8.12.0
  • OS: [osx]
  • Monorepo: [e.g. yes/no/Lerna]
  • How you are using Babel: register@7.4.4

Additional context/Screenshots
I search related stackoverflow problem: https://stackoverflow.com/questions/53808674/using-babel-preset-react-app-with-babel-register

@babel-bot
Copy link
Collaborator

Hey @JennerChen! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Apr 29, 2019

That preset only transpiles modules when NODE_ENV is test: https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/create.js#L69-L92

@JennerChen
Copy link
Author

thanks @nicolo-ribaudo

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants