Skip to content

CRA generating invalid sourcemaps? #4683

Closed
@kenhoff

Description

@kenhoff

tl;dr

Is this a bug report?

Yes. Maybe? I think so.

Did you try recovering your dependencies?

Yup - deleted node_modules and yarn.lock, reinstalled with yarn.

yarn --version is 1.7.0.

Which terms did you search for in User Guide?

sourcemaps, source maps, and eject.

(I'm familiar with ejecting (yarn eject) and manually setting devtool in config/webpack.config.prod.js.)

Environment

Environment:
  OS:  macOS High Sierra 10.13.4
  Node:  9.4.0
  Yarn:  1.7.0
  npm:  5.6.0
  Watchman:  4.9.0
  Xcode:  Not Found
  Android Studio:  Not Found

Packages: (wanted => installed)
  react: ^16.4.1 => 16.4.1
  react-dom: ^16.4.1 => 16.4.1
  react-scripts: 1.1.4 => 1.1.4

Steps to Reproduce

I've set up an example repo at https://github.com/kenhoff/cra-sourcemap-testing.

If you're using that repo:

  1. git clone [email protected]:kenhoff/cra-sourcemap-testing.git
  2. cd cra-sourcemap-testing
  3. yarn
  4. yarn build
  5. node test-sourcemaps.js -> throws error

Otherwise, setting up from scratch:

  1. npx create-react-app my-sourcemap-testing
  2. cd my-sourcemap-testing
  3. yarn build
  4. then, test the build/static/js/main.*.js and build/static/js/main.*.js.map files with sourcemap-validator (https://www.npmjs.com/package/sourcemap-validator)

Expected Behavior

I expected sourcemap-validator to not throw an error, (hypothetically) indicating that the generated sourcemaps are valid.

Actual Behavior

sourcemap-validator and the node test-sourcemaps.js command logs and throws the following error:

[ 'main.a0b7d8d3.js', 'main.a0b7d8d3.js.map' ]
/Users/kenhoff/dev/cra-sourcemap-testing/node_modules/sourcemap-validator/index.js:146
          throw new Error(errMsg);
          ^

Error: Warning: mismatched names
Expected: __webpack_require__ || '__webpack_require__' || '__webpack_require__' || "__webpack_require__" || "__webpack_require__"
Got:    function __webpac ||    function __webpack_ ||          function __webpack_ ||          function __webpack_||      function __webpack_
Original Line:          function __webpack_require__(moduleId) {
Mapping: 1:21→5:0 "__webpack_require__" in ../webpack/bootstrap e71d967440f2e775571f
    at /Users/kenhoff/dev/cra-sourcemap-testing/node_modules/sourcemap-validator/index.js:146:17
    at Array.forEach (<anonymous>)
    at SourceMapConsumer_eachMapping [as eachMapping] (/Users/kenhoff/dev/cra-sourcemap-testing/node_modules/sourcemap-validator/node_modules/source-map/lib/source-map/source-map-consumer.js:570:10)
    at validate (/Users/kenhoff/dev/cra-sourcemap-testing/node_modules/sourcemap-validator/index.js:83:12)
    at fs.readdir (/Users/kenhoff/dev/cra-sourcemap-testing/test-sourcemaps.js:11:9)
    at FSReqWrap.oncomplete (fs.js:149:20)

Reproducible Demo

I've set up an example repo at https://github.com/kenhoff/cra-sourcemap-testing.

If you're using that repo:

  1. git clone [email protected]:kenhoff/cra-sourcemap-testing.git
  2. cd cra-sourcemap-testing
  3. yarn
  4. yarn build
  5. node test-sourcemaps.js -> throws error

Other notes

  • The sourcemaps appear to be valid to my browser (Chrome Version 67.0.3396.87 (Official Build) (64-bit))
  • But, the sourcemaps don't appear to be valid to my Sentry configuration, using the tool here: https://sourcemaps.io/
  • Removing the UglifyJsPlugin from config/webpack.config.prod.js (after ejecting) solves the problem and generates valid sourcemaps, but doesn't minify/uglify the bundled js.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions