Create-react-app: Loading sourcemaps in a monorepo

Created on 28 Feb 2019  ยท  10Comments  ยท  Source: facebook/create-react-app

I have a mono repo structured like this:

.
โ”œโ”€โ”€ node_modules
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ packages
โ”‚ย ย  โ”œโ”€โ”€ app
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ dist
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ App.css
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ App.js
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ App.js.map
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.js
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ index.js.map
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ package.json
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ src
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ App.css
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ App.js
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ index.js
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ yarn.lock
โ”‚ย ย  โ””โ”€โ”€ ui
โ”‚ย ย      โ”œโ”€โ”€ node_modules
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ @taxi
โ”‚ย ย      โ”‚ย ย      โ””โ”€โ”€ app -> ../../../app
โ”‚ย ย      โ”œโ”€โ”€ package.json
โ”‚ย ย      โ”œโ”€โ”€ public
โ”‚ย ย      โ”œโ”€โ”€ src
โ”‚ย ย      โ”œโ”€โ”€ tsconfig.json
โ”‚ย ย      โ””โ”€โ”€ yarn.lock
โ”œโ”€โ”€ tsconfig.build.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ tslint.json
โ”œโ”€โ”€ tslint.prod.json
โ”œโ”€โ”€ tslint.test.json
โ”œโ”€โ”€ yarn-error.log
โ””โ”€โ”€ yarn.lock

the packages/app/package.json file contains:

{
  "name": "@taxi/app",
  "version": "1.0.0",
  "description": "Main application",
  "private": true,
  "main": "/dist/index.js",
  "license": "MIT",
  "peerDependencies": {
    "react": "^16.5.1",
    "styled-components": "^3.4.6"
  },
  "files": [
    "dist"
  ],
  "dependencies": {
    "react": "^16.8.2",
    "react-dom": "^16.8.2"
  }
}

Peer dependencies (i.e. other packages) are linked into node_modules using lerna link.

packages/app is built with:

BABEL_ENV=build babel src --root-mode upward --out-dir dist --source-maps --extensions .js,.ts,.tsx --no-comments --copy-files

packages/ui is a create-react-app application. The app runs correctly and loads objects from packages/app seemingly fine.

I have sourcemap files for the files in packages/app/dist, but I can't get create-react-app to appear to use them correctly. I say correctly, since it does appear to be using them (in Chrome), since the debugger is finding the sourcemap and mapping from the webpack hosted chunk file to the file in dist, but I want to map it to the file in src. I'd really like to debug the source and not the transpiled code.

This seems like a pretty common use case, without ejecting, is there something that I can do to get this working?

stale

Most helpful comment

I've been looking at the reverted monorepo PRs (#3741, #3997, #4001), which appear to do exactly what I'd have desired. I do understand why they were pulled from V2, but they were reverted with a comment that the issue would be solved by "excellent documentation", and as yet, I can't see any, excellent or otherwise.

Can someone who understand how, write some? This is frustrating since my build basically works, but not being able to get sourcemaps working really is a huge stumbling block - and I expect that fixing sourcemaps is specifically an issue with the create-react-app managed webpack config.

All 10 comments

I've been looking at the reverted monorepo PRs (#3741, #3997, #4001), which appear to do exactly what I'd have desired. I do understand why they were pulled from V2, but they were reverted with a comment that the issue would be solved by "excellent documentation", and as yet, I can't see any, excellent or otherwise.

Can someone who understand how, write some? This is frustrating since my build basically works, but not being able to get sourcemaps working really is a huge stumbling block - and I expect that fixing sourcemaps is specifically an issue with the create-react-app managed webpack config.

@ggascoigne did you find any solution for this? I'm currently facing the exact same issue. I tried inline source maps and then started to go over open issues, no luck so far.

Same here, hope to get some answers in this thread

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

[EDIT] actually build suffers the same problem. I was building it directly from source. I agree that at some point first class monorepo support would be great to have.

@ggascoigne looking at those PRs above, can you spot which webpack/babel options made this possible? If I were to eject and try to remedy this myself?

This is also breaking any support from services like bugsnag or sentry. They don't think that the sourcemaps match up with the code (and they are right).

The sourcemaps are right in dev though...

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdamian3 picture rdamian3  ยท  3Comments

alleroux picture alleroux  ยท  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  ยท  3Comments

jnachtigall picture jnachtigall  ยท  3Comments

fson picture fson  ยท  3Comments