systemjs / plugin-babel

SystemJS Babel Plugin
MIT License
83 stars 33 forks source link

problem when I try to run jspm-react boilerplate codebase #51

Closed capaj closed 8 years ago

capaj commented 8 years ago

When running unit tests, I get: (SystemJS) /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:136 $traceurRuntime.canonicalizeUrl = canonicalizeUrl; ^ ReferenceError: $traceurRuntime is not defined at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:136:3 at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:140:3 at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:3859:23 at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:42896:3 at Object.exports.runInThisContext (vm.js:54:17) Evaluating /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js Error loading /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js as "systemjs-babel-build" from /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/plugin-babel.js Error loading /var/www/zahrajeme.cz/public/routes/home.js (SystemJS) /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:136 $traceurRuntime.canonicalizeUrl = canonicalizeUrl; ^ ReferenceError: $traceurRuntime is not defined at public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:136:3 at public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:140:3 at public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:3859:23 at public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js:42896:3 at Object.exports.runInThisContext (vm.js:54:17) Evaluating /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js Error loading /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/systemjs-babel-node.js as "systemjs-babel-build" from /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.10/plugin-babel.js Error loading /var/www/zahrajeme.cz/public/routes/home.js

I am using babel-why would it try to use traceur?

guybedford commented 8 years ago

Make sure to run version 0.0.12 of plugin-babel.

capaj commented 8 years ago

@guybedford that helps, but I have stumbled on another crash in there:

(SystemJS) /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:22574
      var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
                               ^
    TypeError: Cannot read property 'env' of undefined
        at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:22574:28
        at l (/var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:2178)
        at i (/var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:1812)
        at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:2256
        at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:34422:17
        at l (/var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:2178)
        at i (/var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:1812)
        at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:2256
        at /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:39437:15
        at l (/var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/systemjs-babel-node.js:1:2178)
    Evaluating /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/plugin-babel.js
    Error loading /var/www/zahrajeme.cz/public/jspm_packages/npm/systemjs-plugin-babel@0.0.12/plugin-babel.js
    Error loading /var/www/zahrajeme.cz/public/routes/home.js

Which is weird, since I am running it from node.js, so process should be on global scope.

guybedford commented 8 years ago

@capaj is the process global definitely available here?

guybedford commented 8 years ago

Basically, something must nulled out global.process because that doesn't happen in the build file itself.

capaj commented 8 years ago

@guybedford I tried putting console.log(process.env) just before I call System.import('routes/home') and it logged out env variables as it should. It gets nulled somewhere there, I will try a setter to find who is deleting it.

capaj commented 8 years ago

In this case process is not the global process in node, but a locally scoped variable defined as: var process = $__require("3");

image

Is this all built properly @guybedford ?

guybedford commented 8 years ago

If you look at System.registerDynamic("3" you will see it is just exporting global.process though?

capaj commented 8 years ago

so I have found out what is breaking it-the way I instrument those tests:

require('systemjs')
System.config({
  baseURL: 'public/'
})
require('./public/jspm.browser')
require('./public/jspm.config')

require('babel-register')

const Mocha = require('mocha')
const glob = require('glob')
const jsdom = require('jsdom')
const mocha = new Mocha()

const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
const win = doc.defaultView
global.document = doc
global.window = win
global.navigator = win.navigator
// take all properties of the window object and also attach it to the
// mocha global object
propagateToGlobal(win) //this breaks it, when commented out, tests run

// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
function propagateToGlobal (window) {
  for (let key in window) {
   // note that global.process is not overwritten by this
    if (!window.hasOwnProperty(key)) continue
    if (key in global) continue

    global[key] = window[key]
  }
}

The last call to propagateToGlobal breaks it. When I remove it, tests run as expected. Maybe systemjs might get confused about the environment it's running in and fail to supply process to that particular module?

capaj commented 8 years ago

@guybedford yes indeed:

$__System.registerDynamic("3", ["@system-env"], true, function($__require, exports, module) {
  ;
  var define,
      global = this,
      GLOBAL = this;
  var productionEnv = $__require('@system-env').production;
  var pEnv = process.env;
  pEnv.NODE_ENV = productionEnv ? 'production' : 'development';
  module.exports = global.process;
  return module.exports;
});
guybedford commented 8 years ago

Does it work if you change the line module.exports = global.process to just module.exports = process?

capaj commented 8 years ago

@guybedford oh yes. I am a bit confused. Shouldn't they be the same?

EDIT: oh now I see that bit:

  var define,
      global = this,
      GLOBAL = this;
guybedford commented 8 years ago

Sure, I've updated that in the original repo.

capaj commented 8 years ago

@guybedford where was that?

guybedford commented 8 years ago

https://github.com/jspm/nodelibs-process