Electron: issues loading javascripts files with requireJS

Created on 26 May 2014  ·  3Comments  ·  Source: electron/electron

I have been working on a project for months now and I would like to use Atom to embed the app. The project use requireJS and I never encountered scripts loading issue on the web version or even on the node-webkit build however, with Atom, scripts do not load correctly.

I made a small example to illustrate the issue. It is a mac build.
https://github.com/cniaulin/loading-issue

Clone the repo, launch Atom.app. Look if moment is defined, if yes cmd + r, you will see that it is not always the case.
You can display console with cmd + alt + i
Files are located here: Atom.app/Contents/Resources/app/

Does anyone has a solution or a workaround ?

Most helpful comment

@cniaulin A workaround would be to free the require variable by renaming it to something else before loading require.js as follows:

<script>
  if (window.require) {
    window.nodeRequire = window.require;
    delete window.require;
  }
</script>

You'll need to call nodeRequire wherever you want to call Node.js version of require.

All 3 comments

Hi, all i know about requireJs is that they have similar require method with node which conflicted, try use requirejs as subtitute method.

Best practice: Use npm to install Node-only packages/modules into the projects node_modules directory, but do not configure RequireJS to look inside the node_modules directory. Also avoid using relative module IDs to reference modules that are Node-only modules. So, do not do something like require("./node_modules/foo/foo").

look further for http://requirejs.org/docs/node.html

@cniaulin A workaround would be to free the require variable by renaming it to something else before loading require.js as follows:

<script>
  if (window.require) {
    window.nodeRequire = window.require;
    delete window.require;
  }
</script>

You'll need to call nodeRequire wherever you want to call Node.js version of require.

I'm closing this since there is no plan to support requireJS in atom-shell.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tengyifei picture tengyifei  ·  3Comments

PhilAndrew picture PhilAndrew  ·  3Comments

christiangenco picture christiangenco  ·  3Comments

maxogden picture maxogden  ·  3Comments

reggi picture reggi  ·  3Comments