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

Paths set in NODE_PATH are not available in the browser process #11

Closed
probablycorey opened this issue May 17, 2013 · 7 comments
Closed

Comments

@probablycorey
Copy link

I'm trying to move the classes in main.coffee into multiple files, but the browser process's require doesn't know about the paths set on NODE_PATH. This even fails when the first thing main.coffee does is set the NODE_PATH env variable.

@zcbenz
Copy link
Member

zcbenz commented May 18, 2013

When the main.coffee is loaded, the NODE_PATH has already been read and stored by the module system, so subsequent modifications to NODE_PATH won't have any effect on current script.

To modify the module's search paths in main.coffee, you should append the paths to require('module').globalPaths:

require('module').globalPaths.push(searchPath);

This feature (modify the search paths after script is loaded) is atom-shell only, I'll document it.

@zcbenz zcbenz closed this as completed May 18, 2013
@probablycorey
Copy link
Author

Do you think we should use module.globalPaths instead of NODE_PATH for everything? It would be more consistent, but are there are downsides?

@zcbenz
Copy link
Member

zcbenz commented May 21, 2013

module.globalPaths does not work in the renderer, because of a hack that forcing module code to be evaluated under window context.

@probablycorey
Copy link
Author

I can't get module.globalPaths to work in the browser process.

I run this code in main.coffee

  console.log require('module').globalPaths
  require('module').globalPaths.push(resourcePath + "/src/app")
  console.log require('module').globalPaths
  require('point')

And this is the output

[ '/Users/corey/.node_modules',
  '/Users/corey/.node_libraries',
  '/Applications/Atom.app/Contents/lib/node',
  '/Applications/Atom.app/Contents/Resources/browser/api/lib',
  '/Applications/Atom.app/Contents/Resources/common/api/lib' ]
[ '/Users/corey/.node_modules',
  '/Users/corey/.node_libraries',
  '/Applications/Atom.app/Contents/lib/node',
  '/Applications/Atom.app/Contents/Resources/browser/api/lib',
  '/Applications/Atom.app/Contents/Resources/common/api/lib',
  '/Users/corey/github/atom/src/app' ]
uncaughtException:
Error: Cannot find module 'point'
    at Function.Module._resolveFilename (module.js:351:15)
    at Function.Module._load (module.js:293:25)
    at Module.require (module.js:377:17)
    at require (module.js:393:17)
    at Object.bootstrapApplication [as preMainMessageLoopRun] (/Applications/Atom.app/Contents/Resources/app/src/main.js:76:12)

@probablycorey probablycorey reopened this May 23, 2013
@zcbenz
Copy link
Member

zcbenz commented May 24, 2013

The ~/github/atom only contains .coffee sources, so you have to require coffee-script:

require('coffee-script')
require('coffee-cache').setCacheDir('/tmp/atom-coffee-cache')
require('module').globalPaths.push(resourcePath + "/src/app")
require('point')

@probablycorey
Copy link
Author

Ahh, thanks!

zcbenz pushed a commit that referenced this issue Jan 16, 2016
zcbenz pushed a commit that referenced this issue Jun 26, 2016
minggo added a commit to minggo/electron that referenced this issue Sep 6, 2016
* add option to disable devtools

* beautify codes

* initialize disable_devtools_
kevinsawicki pushed a commit that referenced this issue May 9, 2017
* vendor/libchromiumcontent e70a88f...4aae27b (2):
  > Merge pull request #11 from brightray/windows-build
  > Merge pull request #10 from brightray/windows-scripts
kevinsawicki pushed a commit that referenced this issue May 9, 2017
* vendor/libchromiumcontent e70a88f...4aae27b (2):
  > Merge pull request #11 from brightray/windows-build
  > Merge pull request #10 from brightray/windows-scripts
@release-notifier
Copy link

This PR landed in electron v1.7.12 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants