rixo / svelte-template-hot

Copy of official Svelte template with added HMR support
61 stars 9 forks source link

DevTools failed to load SourceMap with nollup only #9

Open frederikhors opened 4 years ago

frederikhors commented 4 years ago

I'm trying to use the amazing @urql/svelte.

It works both with nollup and rollup.

But with nollup I have these warnings in console:

image

DevTools failed to load SourceMap: Could not load content for http://localhost:5000/node_modules/@urql/core/dist/2b2328af.mjs.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load SourceMap: Could not load content for http://localhost:5000/node_modules/@urql/svelte/dist/urql-svelte.mjs.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

Reproduction here: https://github.com/frederikhors/svelte-template-hot/tree/urql-svelte-sourcemap-warnings

Why?

frederikhors commented 4 years ago

Edit: Added reproduction project.

rixo commented 4 years ago

I have no real idea how sourcemaps works in Nollup (or generally otherwise...), but you can probably fix this by adding a middleware to serve contents from /node_modules/ if that's important to you.

Add a .nolluprc.js file to your project with something like this:

const path = require('path')
const fs = require('fs')

module.exports = {
  before(app) {
    app.get('/node_modules/*', (req, res, next) => {
      const file = path.resolve(__dirname, req.url.replace(/^\//, ''))
      fs.exists(file, exists => {
        if (exists)res.sendFile(file)
        else next()
      })
    })
  }
}
frederikhors commented 4 years ago

Wow it works!

But I have totally no idea what I'm doing.

Does it impact performance in your opinion?

Can it affect the final bundle created with npm run build?

rixo commented 4 years ago

I was surely tired previously, it's obviously not a sourcemap problem. It's a more of a dev server problem.

No it wouldn't impact performance in any meaningful way... Like we're speaking less than a ms or so per request. And it wouldn't end up in prod build. Nollup doesn't do prod build. It doesn't do build at all actually. It just does fast dev server mostly compatible with Rollup config. It is intended that you produce your prod bundle with Rollup.