Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Source map wrong for JS files #327

Open
azizghuloum opened this issue May 18, 2018 · 7 comments
Open

Source map wrong for JS files #327

azizghuloum opened this issue May 18, 2018 · 7 comments

Comments

@azizghuloum
Copy link

Is this a bug report?

Yes

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

Didn't try. I think this is irrelevant. I have 5.6.0

Which terms did you search for in User Guide?

map source lines

Environment

  1. npm ls react-scripts-ts (if you haven’t ejected):
    react-scripts-ts@2.16.0

  2. node -v:
    v8.11.2

  3. npm -v:
    5.6.0

  4. yarn --version (if you use Yarn):
    1.5.1

  5. npm ls react-scripts-ts (if you haven’t ejected):
    Is this different from 1?

Then, specify:

  1. Operating system:
    Mac OS 10.13.3

  2. Browser and version (if relevant):
    Chrome 66

Steps to Reproduce

(Write your steps here:)

  1. create a fresh app and ensure all is working
$ create-react-app test-ts --scripts-version=react-scripts-ts
$ cd test-ts
$ yarn run start

(I also added "allowSyntheticDefaultImports": true to tsconfig.json but that's irrelevant)

  1. Create a file Foo.tsx containing:
import React from "react";

const Foo = () => <div>
  Hello in Foo.js
  {somethingThatThrows()}
</div>;

const somethingThatThrows = () => {
  throw new Error("HERE");
};

export default Foo;

Use it from App.tsx and notice that the error line numbers and highlights in the browser are absolutely 100% correct (see screenshot).

screenshot-ts

  1. Rename the file to Foo.js and restart yarn run start.

Expected Behavior

That the output error is in the exact same place.

Actual Behavior

The source maps are messed up and the highlighted lines is wrong. (see screenshot)

screenshot-js

Reproducible Demo

It's pretty straightforward to produce. Available upon request. :-)

We have a huge project that we're migrating to typescript and not having source map along the trip will cause huge frustration.

Thank you in advance for your help.

@wilcus
Copy link

wilcus commented Jun 15, 2018

@azizghuloum To solve this I have to change devtool to 'source-map' in webpack-config-dev. I'd ejected the project before.

module.exports = {
  devtool: 'source-map',

@fc
Copy link

fc commented Jul 27, 2018

in config-overrides.js, you can also do this:

module.exports = function override(config, env) {
  // ..
  config.devtool = 'source-map';
  return config;
};

@shobhitg
Copy link

shobhitg commented Nov 3, 2018

@wilcus and @fc

I am having this same issue (#440).

But looks like this workaround won't work because I will have to change everytime I do yarn install in my local version:
https://github.com/wmonk/create-react-app-typescript/blob/master/config/webpack.config.dev.js#L40

I would have to change from devtool: 'cheap-module-source-map' to devtool: 'source-map' every time in ./node_modules/react-scripts-ts/config/webpack.config.dev.js.

Is there a workaround where I can create some config file in root of my project to solve this issue?

@fc
Copy link

fc commented Nov 3, 2018

@shobhitg As of create-react-app 2.1.0, it now supports TypeScript, is there a reason you cannot use that?
https://github.com/facebook/create-react-app/releases

@shobhitg
Copy link

shobhitg commented Nov 4, 2018

@fc I had started my project a month before official CRA 2.1.0 came out.

Things were going fine and I had no reason to budge until I hit this .jsx source-map issue.

Also I heard there were some differences in CRA 2.1.0 (babel based) and this react-scripts-ts (tsc-loader based). Something about enums not being supported in Babel's TS, but I don't remember exact.

I will give CRA 2.1.0 a shot. But don't know if there would be any hurdles in converting the project.

But I really wish this react-scripts-ts project had a way to customize webpack config.

@shobhitg
Copy link

shobhitg commented Nov 4, 2018

I tried CRA 2.1.0.

I ran npx create-react-app hello-tsx --typescript.
But the files that were created were all .js.

@fc
Copy link

fc commented Nov 4, 2018

It looks like the jsx file extension is supported according their source:
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.dev.js#L229-L234

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

4 participants