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

🗺 v2 sourcemaps not working (totally NOT styled-components related) #6278

Closed
shelldandy opened this issue Jul 3, 2018 · 11 comments · Fixed by #10083
Closed

🗺 v2 sourcemaps not working (totally NOT styled-components related) #6278

shelldandy opened this issue Jul 3, 2018 · 11 comments · Fixed by #10083
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@shelldandy
Copy link
Contributor

shelldandy commented Jul 3, 2018

Steps to reproduce

Start a new Gatsby project on v2

Expected result

Sourcemaps show original file names/code to debug (at least in development)

Actual result

screen shot 2018-07-03 at 11 54 48 am

Sourcemaps shown already compiled code 🤔

Environment

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
    Shell: 2.7.1 - /usr/local/bin/fish
  Binaries:
    Node: 8.11.1 - ~/.nvm/versions/node/v8.11.1/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.1.0 - ~/.nvm/versions/node/v8.11.1/bin/npm
  Browsers:
    Chrome: 67.0.3396.99
    Firefox: 58.0
    Safari: 11.1.1
  npmPackages:
    gatsby: ^2.0.0-beta.21 => 2.0.0-beta.21
@giraffesyo
Copy link
Contributor

I have styled components working here, but I'm not using the gatsby plugin. I'm wondering, do you also have the package styled-components added? It's a peer dependency now.

v2.0.1
styled-components is moved to a peer dependency. Installing the package alongside gatsby-plugin-styled-components is now required. Use npm install --save styled-components

@shelldandy
Copy link
Contributor Author

shelldandy commented Jul 3, 2018

Yes it's added, i mean styled-components work, sourcemaps dont

Edit: Not 💅 related, purely Gatsby v2 related, 😄

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Jul 4, 2018
@shelldandy
Copy link
Contributor Author

shelldandy commented Jul 4, 2018

Since the styled-components plugin doesn't change any webpack config i think this is an issue with gatsby v2 purely I fixed it as follows:

gatsby-node.js

exports.onCreateWebpackConfig = ({ stage, actions }) => {
	if (stage === 'develop') {
		actions.setWebpackConfig({
			devtool: 'cheap-module-source-map'
		});
	}
};

That way the sourcemaps are properly loaded:

screen shot 2018-07-04 at 1 34 57 pm

I went with cheap-module-source-map since that's what react-scripts is doing

@shelldandy
Copy link
Contributor Author

So now I think this could become a bug hunt for v2 towards why aren't sourcemaps properly loading to begin with???

🤔

@shelldandy
Copy link
Contributor Author

But major props to the fact that as users we can tweak and fix those inner configs ourselves!

Top reason I choose Gatsby!

@shelldandy
Copy link
Contributor Author

Any thoughts @giraffesyo 😮 ?

@giraffesyo
Copy link
Contributor

@shelldandy Nope sorry, I haven't used sourcemaps yet. I misunderstood the original question to be about styled-components :(

@shelldandy shelldandy changed the title 🗺 v2 with styled-components not working sourcemaps 🗺 v2 sourcemaps not working Jul 5, 2018
@shelldandy
Copy link
Contributor Author

I thought initially that was related but later on discovered its not.

I've updated the title and original description to be more fit @giraffesyo

@KyleAMathews
Copy link
Contributor

Do sourcemaps not work for any parts of Gatsby v2? Or is this a styled-components specific issue?

@shelldandy
Copy link
Contributor Author

shelldandy commented Jul 5, 2018

Any parts of Gatsby v2, you can open it up on Chrome Developer tool and for example this non-styled-components non-react just vanillaJS code looks like that:

When it should look like this:

(It looks like that after I apply the fix on gatsby-node.js

What I can see is that Gatbsy by default sets the devtool for development as "eval" based on:

function getDevtool() {
switch (stage) {
case `develop`:
return `eval`
// use a normal `source-map` for the html phases since
// it gives better line and column numbers
case `develop-html`:
case `build-html`:
case `build-javascript`:
return `source-map`
default:
return false
}
}

However for some reason eval shows up in the devtools as post compiled code which isn't really that helpful debugging vs cheap-module-source-map which as you can see renders full sourcecode on the console and breakpoints also work really well.

So it might be just a plugin order situation on the final webpack config happening behind the scenes (?)

That's all the insights I got so far @giraffesyo @KyleAMathews

@shelldandy shelldandy changed the title 🗺 v2 sourcemaps not working 🗺 v2 sourcemaps not working (totally NOT styled-components related) Jul 5, 2018
@wking-io
Copy link

This was a problem back in v1 and @KyleAMathews fixed it here: f5191a0

However, it looks like the same issue is back on v2:

pieh pushed a commit that referenced this issue Nov 22, 2018
…evelop mode for easier debugging (#10083)

Closes #6278

Sourcemaps are not currently working on gatsby v2. This fixes that on 1 string.
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this issue Jan 22, 2019
…evelop mode for easier debugging (gatsbyjs#10083)

Closes gatsbyjs#6278

Sourcemaps are not currently working on gatsby v2. This fixes that on 1 string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
5 participants