Experience-Monks / devtool

[OBSOLETE] runs Node.js programs through Chromium DevTools
MIT License
3.77k stars 150 forks source link

Improving --no-browser-globals #29

Closed mattdesl closed 8 years ago

mattdesl commented 8 years ago

Since #23 I have added --no-browser-globals which was a first attempt at solving some issues with node modules that rely on window / document / etc (i.e. doing some node-type code if window is undefined).

This causes some new issues in some cases: https://twitter.com/yaypie/status/692127048773550080

The problem is basically here: https://github.com/zloirock/core-js/blob/270fabccd38e0210caf1a4ffc44ca328880fba69/modules/_global.js

console.log(Function('return this')())

Where this in that context evaluates to window...

rgrove commented 8 years ago

One more --no-browser-globals issue from my app: my entry point script has a shebang as its first line, which causes additional confusion:

160126hr0og

Thanks for reaching out and offering to help, btw! Devtool looks super promising.

mattdesl commented 8 years ago

@rgrove I can't seem to reproduce the shebang parse error. Can you add any details here? https://github.com/Jam3/devtool/issues/30

mattdesl commented 8 years ago

@rgrove I've made some fixes to the following:

Can you test again with devtool@1.7.1?

rgrove commented 8 years ago

@mattdesl 1.7.1 gets further, and the shebang parse error is gone now! Still getting lots of SyntaxError: Unexpected end of input errors though, and after a bunch of these my app finally crashes since it can't properly initialize itself.

When I look at the files that are causing the errors, the one thing that stands out is that none of them end with a newline. I added an ending newline to one of them and, sure enough, the SyntaxError disappeared.

Here's the latest console output, in case it helps:

Error compiling module: /Users/rgrove/src/cake/www/node_modules/core-js/library/modules/$.global.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/core-js/library/modules/$.export.js:1:131)
    at Module._compile (module.js:425:26)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/core-js/library/modules/$.iter-define.js:3:22)
    at Module._compile (module.js:425:26)
Error compiling module: /Users/rgrove/src/cake/www/node_modules/core-js/library/modules/$.core.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/core-js/library/modules/$.export.js:2:17)
    at Module._compile (module.js:425:26)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/core-js/library/modules/$.iter-define.js:3:22)
    at Module._compile (module.js:425:26)
Error compiling module: /Users/rgrove/src/cake/www/node_modules/babel-core/node_modules/babel-traverse/lib/path/constants.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babel-core/node_modules/babel-traverse/lib/path/index.js:21:18)
    at Module._compile (module.js:425:26)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:13:13)
    at Module._compile (module.js:425:26)
Error compiling module: /Users/rgrove/src/cake/www/node_modules/babel-traverse/lib/path/constants.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babel-traverse/lib/path/index.js:21:18)
    at Module._compile (module.js:425:26)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babel-traverse/lib/context.js:13:13)
    at Module._compile (module.js:425:26)
Error compiling module: /Users/rgrove/src/cake/www/node_modules/babylon/lib/tokenizer/state.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babylon/lib/tokenizer/index.js:19:14)
    at Module._compile (module.js:425:26)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babylon/lib/parser/index.js:19:18)
    at Module._compile (module.js:425:26)
Error compiling module: /Users/rgrove/src/cake/www/node_modules/babel-generator/node_modules/babel-traverse/lib/path/constants.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babel-generator/node_modules/babel-traverse/lib/path/index.js:21:18)
    at Module._compile (module.js:425:26)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/rgrove/src/cake/www/node_modules/babel-generator/node_modules/babel-traverse/lib/context.js:13:13)
    at Module._compile (module.js:425:26)
Error compiling module: /Users/rgrove/src/cake/www/node_modules/babel-helper-builder-react-jsx/lib/index.js
Unexpected end of input
SyntaxError: Unexpected end of input
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at devtoolCompileModule (/usr/local/lib/node_modules/devtool/lib/require-hook.js:37:14)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/rgrove/src/cake/www/node_modules/babel-register/lib/node.js:138:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at exports.default (/Users/rgrove/src/cake/www/node_modules/babel-plugin-transform-react-jsx/lib/index.js:12:17)
    at Function.memoisePluginContainer (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:127:13)
    at Function.normalisePlugin (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:161:32)
    at /Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:197:30
    at Array.map (native)
    at Function.normalisePlugins (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
    at OptionManager.mergeOptions (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
    at OptionManager.mergePresets (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:325:16)
TypeError: require(...) is not a function
    at exports.default (/Users/rgrove/src/cake/www/node_modules/babel-plugin-transform-react-jsx/lib/index.js:12:58)
    at Function.memoisePluginContainer (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:127:13)
    at Function.normalisePlugin (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:161:32)
    at /Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:197:30
    at Array.map (native)
    at Function.normalisePlugins (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
    at OptionManager.mergeOptions (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
    at OptionManager.mergePresets (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:325:16)
    at OptionManager.mergeOptions (/Users/rgrove/src/cake/www/node_modules/babel-core/lib/transformation/file/options/option-manager.js:287:12)
    at compile (/Users/rgrove/src/cake/www/node_modules/babel-register/lib/node.js:85:15)
    at loader (/Users/rgrove/src/cake/www/node_modules/babel-register/lib/node.js:130:14)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/rgrove/src/cake/www/node_modules/babel-register/lib/node.js:140:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
mattdesl commented 8 years ago

Ok, I managed to get this universal webpack boilerplate running/debugging inside devtool with a few more tweaks (see 1.7.2). I think we will have to keep testing on real-world apps to track down any more problems.

I will probably need some isolated test to fix the above bugs since it isn't clear where the problem is.

Thanks again!

mattdesl commented 8 years ago

Update: the "Unexpected end of input" was just a silly typo on the way I was wrapping modules in a closure (forgot a new line). So at least now that bug is fixed in 1.7.3.

rgrove commented 8 years ago

Hooray! As of 1.7.3, devtool runs my app perfectly. Thanks for all the help, @mattdesl!

mattdesl commented 8 years ago

Awesome! I am going to close this. I'm sure something else will come up eventually, feel free to post a new issue when/if it breaks. :smile:

bsr203 commented 8 years ago

hi @mattdesl I have react/webpack project, and use tape for testing. Testing works great with tape, but sometimes I really needed devtool to trace error. Do you think it is possible to use it with above stack. An example with any of the react boiler plates out there would be awesome. thanks a ton for your help.