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

App works with start but not with build + serve #3312

Closed
fozzle opened this issue Oct 23, 2017 · 2 comments
Closed

App works with start but not with build + serve #3312

fozzle opened this issue Oct 23, 2017 · 2 comments

Comments

@fozzle
Copy link

fozzle commented Oct 23, 2017

Is this a bug report?

Hm, sort of? Could very well be user error.

Can you also reproduce the problem with npm 4.x?

Symptoms are the same no matter Yarn, NPM4, or NPM5.

Which terms did you search for in User Guide?

Just looked over the build and deployment settings.

Environment

  1. node -v: 8.1.3
  2. npm -v: 4.6.1
  3. yarn --version (if you use Yarn): 1.0.1
  4. npm ls react-scripts (if you haven’t ejected): 1.0.14

Then, specify:

  1. Operating system: MacOS
  2. Browser and version (if relevant): Chrome 61

Steps to Reproduce

Basically, my project works if I use yarn start but not if I yarn build and then serve -s build

(Write your steps here:)

  1. Clone this https://github.com/fozzle/react-burrito-type-example and install dependencies
  2. Use yarn start to observe a seemingly functional project
  3. Use yarn build and serve -s build to observe a very broken project

Expected Behavior

I thought the built code would work, as the watched code did.

Actual Behavior

I get a cryptic react error. A cursory search reveals that this may lay in mismatched react versions, but I'm not sure how it can be that if the watched version works fine.

Error:

Uncaught TypeError: Cannot read property 'getStackAddendumByID' of undefined
    at eval (webpack-internal:///28:4953)
    at Object.eval (webpack-internal:///28:17220)
    at eval (webpack-internal:///28:17223)
    at Object.<anonymous> (index.js:265)
    at e (index.js:21)
    at Object.eval (webpack-internal:///24:37)
    at eval (webpack-internal:///24:40)
    at Object.<anonymous> (index.js:237)
    at e (index.js:21)
    at Object.eval (webpack-internal:///23:14)

If I look at the included react and react-dom in inspector, they both appear to be v16

Reproducible Demo

I'm trying to make an example for an NPM module I'm publishing. I'm not very well versed in this so it could be my fault but the fact that it works when using yarn start does raise some eyebrows so I thought I'd bring it up.

project github: https://github.com/fozzle/react-burrito-type-example
url of 'deployed code' with error: https://kpetrovi.ch/react-burrito-type-example

@fozzle fozzle changed the title App appears to work with start but not when built + serve App appears to work with start but not with build + serve Oct 23, 2017
@fozzle fozzle changed the title App appears to work with start but not with build + serve App works with start but not with build + serve Oct 23, 2017
@gaearon
Copy link
Contributor

gaearon commented Nov 3, 2017

Even in yarn start mode, you can see that the app has two Reacts:

screen shot 2017-11-03 at 5 21 05 pm

Otherwise it wouldn’t log twice. 😉

If I look into the build output of the react-burrito-type component you published, it includes the whole React source code in its bundle. Additionally, it is very inefficient because all code is evaled.

You need to fix the webpack config of your library to:

  • Not use the devtool setting so that the code isn’t terribly slow and bloated with sourcemaps.
  • Use the externals option to not include react or react-dom into your library bundle.

Hope this helps!

@gaearon gaearon closed this as completed Nov 3, 2017
@fozzle
Copy link
Author

fozzle commented Nov 13, 2017

AH. I believe I was not using react-dom as an external as well. And thanks for the devtool input.

Big oops, very embarrassing. Thanks for your help.

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants