lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

'Cannot find module' with mocks #25

Closed Kordonme closed 8 years ago

Kordonme commented 8 years ago

Already scratched my head for far too long...

[22:57:00] Error: Cannot find module 'mocks\servers.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

Got this config:

lws({
    'static': {
        'root': './'
    },
    'mocks': [{
        'route': '/',
        'module': '/mocks/servers.js'
    }]
}).listen(2650)

Happens on line 151. Basically, it's not able to load the file. However, if I remove the 'module' property, the server starts (of course), and I'm able to navigate to /mocks/servers.js and get the content.

75lb commented 8 years ago

this line:

[22:57:00] Error: Cannot find module 'mocks\servers.js'

why does it include a backslash (the escape character) rather than a forward slash? odd..

75lb commented 8 years ago

are you on Windows? if so, which version?

Kordonme commented 8 years ago

That is odd, yes. Didn't notice that. And yes, Windows 10, node --version: v5.1.1

Kordonme commented 8 years ago

I tried putting the mock js file (servers.js) in same directory. Works fine. Is this a module loading problem on Windows maybe?

75lb commented 8 years ago

checking now, should be a quick fix

75lb commented 8 years ago

finally reproduced after testing on Windows 8 and 10.. while i fix, please test this config for me (static option value removed).. it should behave the same as ws defaults to the current directory..

lws({
    'mocks': [{
        'route': '/',
        'module': '/mocks/servers.js'
    }]
}).listen(2650)
Kordonme commented 8 years ago

Thanks!

I tried that already and I'm getting an error:

[00:07:46] TypeError: Path must be a string. Received undefined
    at assertPath (path.js:8:11)
    at Object.win32.join (path.js:221:5)

Same line in local-web-server.js.

75lb commented 8 years ago

fixed in v1.0.2.. please update and try again.

Kordonme commented 8 years ago

You are the best - works like a charm!

75lb commented 8 years ago

good, pleased you like it! If you have any other ideas about how to improve it, let me know :+1: