Coder Social home page Coder Social logo

Comments (7)

zcbenz avatar zcbenz commented on May 3, 2024 1

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.

from electron.

probablycorey avatar probablycorey commented on May 3, 2024

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

from electron.

zcbenz avatar zcbenz commented on May 3, 2024

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

from electron.

probablycorey avatar probablycorey commented on May 3, 2024

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)

from electron.

zcbenz avatar zcbenz commented on May 3, 2024

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')

from electron.

probablycorey avatar probablycorey commented on May 3, 2024

Ahh, thanks!

from electron.

release-notifier avatar release-notifier commented on May 3, 2024

This PR landed in electron v1.7.12 🎉

from electron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.