insin / nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
Other
5.57k stars 331 forks source link

source-maps not working when not starting via "nwb serve" #178

Open morostr opened 8 years ago

morostr commented 8 years ago

I need to simulate a server in my project, and managed to piece together something that works using "Using nwb in Your Own Express Server via Middleware" (link is a bit wonky, you might not end up on the right chapter, but you are on the right page)

However, now source-maps won't work. At least every line of code can be found at (index):xxx according to chromes debugger. I'm guessing "nwb serve" is doing some magic, but I don't know what. I can only barely understand what I'm doing here as I'm new to both node, webpack, react and everything really.

I am starting the server with "node server.js".

package.json

{
  "name": "nwb-thinking-in-react",
  "version": "1.0.0",
  "description": "Describe nwb-thinking-in-react here",
  "private": true,
  "scripts": {
    "build": "nwb build-react-app",
    "clean": "nwb clean-app",
    "start": "node server.js",
    "test": "nwb test",
    "test:coverage": "nwb test --coverage",
    "test:watch": "nwb test --server"
  },
  "dependencies": {
    "bootstrap": "^3.3.7",
    "react": "^15.3.1",
    "react-dom": "^15.3.1",
    "react-redux": "^4.4.5",
    "redux": "^3.5.2",
    "redux-saga": "^0.11.1",
    "isomorphic-fetch": "latest"
  },
  "devDependencies": {
    "express": "^4.14.0",
    "nwb": "0.12.x"
  },
  "author": "",
  "license": "MIT",
  "repository": ""
}

relevant lines from server.js:

var express = require('express')
var app = express();
// Pass the express module to nwb's middleware
app.use(require('nwb/express')(express));

app.get('/getNode', function(req, res) {
 // .... code
});

app.listen(3000, function(err) {
    if (err) {
        console.error('error starting server:');
        console.error(err.stack);
        process.exit(1);
    }
    console.log('server listening at http://localhost:3000');
})
tomitrescak commented 8 years ago

I can confirm this behaviour. The only way to make sourcemaps work is to turn no "devtool": "source-map". None of the "cheap" methods except for "eval" seem to work.

[EDIT] 'cheap-source-map' seems to work as well.

MethodGrab commented 8 years ago

Looks like the same issue as (or at least related to) #177 ?