brunch / brunch

:fork_and_knife: Web applications made easy. Since 2011.
https://brunch.io
MIT License
6.8k stars 434 forks source link

Module repertories with '.js' #1218

Closed zecaptus closed 8 years ago

zecaptus commented 8 years ago

Description

Example : module 'spin.js'

Uncaught Error: Cannot find module "spin" from "react-spinjs"

vendor.js file

require.register('react-spinjs', function(exports,req,module){
      var require = __makeRequire((function(n) { return req(n.replace('./', 'react-spinjs//lib/')); }), {}, 'react-spinjs');
      (function(exports,require,module) {
        'use strict';

[...]

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _spinJs = require('spin.js');
require.register('spin.js', function(exports,req,module){
      var require = __makeRequire((function(n) { return req(n.replace('./', 'spin.js//')); }), {}, 'spin.js');
      (function(exports,require,module) {

[ ... ]

      })(exports,require,module);
    });require.register('spin.js/spin', function(exports,require,module) {
    module.exports = require('spin.js');
  });

Environment

  1. Brunch: 2.4.2
  2. Node: v5.4.1
  3. NPM: 3.3.12
  4. Operating system: MacOS
goshacmd commented 8 years ago

Changes in #1194 should address this issue

nblackburn commented 8 years ago

@goshakkk Do you have a rough ETA on when these changes will be merged?

goshacmd commented 8 years ago

@zecaptus @nblackburn since that PR was merged, can you confirm if a) modules with .js in their name work properly; b) anything else didn't break?

nblackburn commented 8 years ago
brunch build --debug
brunch:speed Created BrunchWatcher 275ms +0ms
brunch:application Trying to load brunch-config +2ms
brunch:speed Loaded config 306ms +29ms
brunch:speed Loading plugins 307ms +1ms
brunch:plugins Loaded plugins:  +1ms
brunch:speed Loaded plugins 308ms +0ms
brunch:speed Loaded watcher 309ms +1ms
brunch:watch add package.json +14ms
brunch:watch add brunch-config.js +1ms
brunch:watch add app/bootstrap.js +3ms
brunch:list Reading app/bootstrap.js +1ms
brunch:speed Starting compilation 329ms +1ms
brunch:watch add app/api/auth.js +4ms
brunch:list Reading app/api/auth.js +0ms
brunch:watch add app/assets/.htaccess +1ms
brunch:asset Init app/assets/.htaccess directory=app/assets/ relativePath=.htaccess destinationPath=public/.htaccess +2ms
brunch:watch add app/assets/favicon.ico +1ms
brunch:asset Init app/assets/favicon.ico directory=app/assets/ relativePath=favicon.ico destinationPath=public/favicon.ico +0ms
brunch:watch add app/assets/index.html +1ms
brunch:asset Init app/assets/index.html directory=app/assets/ relativePath=index.html destinationPath=public/index.html +0ms
brunch:watch add app/assets/robots.txt +0ms
brunch:asset Init app/assets/robots.txt directory=app/assets/ relativePath=robots.txt destinationPath=public/robots.txt +0ms
brunch:watch add app/components/dashboard.vue +1ms
brunch:list Reading app/components/dashboard.vue +0ms
brunch:watch add app/components/error.vue +0ms
brunch:list Reading app/components/error.vue +0ms
brunch:watch add app/config/routes.js +0ms
brunch:list Reading app/config/routes.js +0ms
brunch:watch add app/state/mutations.js +1ms
brunch:list Reading app/state/mutations.js +0ms
brunch:watch add app/state/store.js +0ms
brunch:list Reading app/state/store.js +0ms
brunch:watch add app/styles/accordion.less +1ms
brunch:list Reading app/styles/accordion.less +1ms
brunch:watch add app/styles/alert.less +0ms
brunch:list Reading app/styles/alert.less +0ms
brunch:watch add app/styles/badge.less +0ms
brunch:list Reading app/styles/badge.less +0ms
brunch:watch add app/styles/base.less +0ms
brunch:list Reading app/styles/base.less +0ms
brunch:watch add app/styles/block.less +1ms
brunch:list Reading app/styles/block.less +0ms
brunch:watch add app/styles/breadcrumb.less +0ms
brunch:list Reading app/styles/breadcrumb.less +0ms
brunch:watch add app/styles/button.less +0ms
brunch:list Reading app/styles/button.less +0ms
brunch:watch add app/styles/column.less +1ms
brunch:list Reading app/styles/column.less +0ms
brunch:watch add app/styles/datepicker.less +0ms
brunch:list Reading app/styles/datepicker.less +0ms
brunch:watch add app/styles/dropdown.less +0ms
brunch:list Reading app/styles/dropdown.less +0ms
brunch:watch add app/styles/form.less +0ms
brunch:list Reading app/styles/form.less +0ms
brunch:watch add app/styles/grid.less +1ms
brunch:list Reading app/styles/grid.less +0ms
brunch:watch add app/styles/list.less +0ms
brunch:list Reading app/styles/list.less +0ms
brunch:watch add app/styles/modal.less +0ms
brunch:list Reading app/styles/modal.less +0ms
brunch:watch add app/styles/nav.less +1ms
brunch:list Reading app/styles/nav.less +0ms
brunch:watch add app/styles/navbar.less +0ms
brunch:list Reading app/styles/navbar.less +0ms
brunch:watch add app/styles/notify.less +0ms
brunch:list Reading app/styles/notify.less +0ms
brunch:watch add app/styles/overlay.less +1ms
brunch:list Reading app/styles/overlay.less +0ms
brunch:watch add app/styles/pagination.less +0ms
brunch:list Reading app/styles/pagination.less +0ms
brunch:watch add app/styles/panel.less +0ms
brunch:list Reading app/styles/panel.less +0ms
brunch:watch add app/styles/range.less +0ms
brunch:list Reading app/styles/range.less +0ms
brunch:watch add app/styles/svg.less +0ms
brunch:list Reading app/styles/svg.less +1ms
brunch:watch add app/styles/switchbox.less +0ms
brunch:list Reading app/styles/switchbox.less +0ms
brunch:watch add app/styles/switcher.less +0ms
brunch:list Reading app/styles/switcher.less +0ms
brunch:watch add app/styles/tab.less +1ms
brunch:list Reading app/styles/tab.less +0ms
brunch:watch add app/styles/table.less +0ms
brunch:list Reading app/styles/table.less +0ms
brunch:watch add app/styles/text.less +0ms
brunch:list Reading app/styles/text.less +0ms
brunch:watch add app/styles/tooltip.less +0ms
brunch:list Reading app/styles/tooltip.less +1ms
brunch:watch add app/styles/utility.less +0ms
brunch:list Reading app/styles/utility.less +0ms
brunch:watch add app/styles/variables.less +0ms
brunch:list Reading app/styles/variables.less +0ms
brunch:watch add app/styles/wizard.less +0ms
brunch:list Reading app/styles/wizard.less +0ms
brunch:asset Copied app/assets/.htaccess +10ms
brunch:asset Copied app/assets/index.html +1ms
brunch:asset Copied app/assets/robots.txt +0ms
brunch:asset Copied app/assets/favicon.ico +3ms
brunch:watch add app/state/modules/user.js +0ms
brunch:list Reading app/state/modules/user.js +0ms
brunch:watch add app/assets/assets/images/logo.svg +4ms
brunch:asset Init app/assets/assets/images/logo.svg directory=app/assets/ relativePath=assets/images/logo.svg destinationPath=public/assets/images/logo.svg +1ms
brunch:speed Watcher is ready 370ms +1ms
brunch:asset Copied app/assets/assets/images/logo.svg +0ms
brunch:write Writing 0/0 files +69ms
04 Mar 09:36:19 - info: copied 5 files in 440ms

Doesn't seem to be writing any files when installing the edge version, rolling back to the latest stable works fine builds fine but with the issue as expected.

goshacmd commented 8 years ago

@nblackburn did you forget to run npm install? It is probably caused by the js/sass/css brunch plugins not being present in node_modules


An edge version of commonjs-require-definition is also needed for these changes to work properly, and there's a typo in master that https://github.com/brunch/commonjs-require-definition/pull/15 will resolve, but it's not merged yet.

Probably hold off your horses for now if you don't want to get into that :)

nblackburn commented 8 years ago

@goshakkk Definitely ran that as i did npm install brunch/brunch --save-dev as the other required packages already existed.

EDIT: Reinstalled the packages and it works and can also require a module with an extension but now have another issue which is related to the issue you mentioned above.

zecaptus commented 8 years ago

You have to replace your brunch line in package.json by : "brunch": "git+https://github.com/brunch/brunch.git#master",

For me, I have to test without my nameCleaner, but I think brunch require all module with '.js' Example : Cannot find module "react/lib/React" from "react/react.js"

zecaptus commented 8 years ago

@nblackburn : ok thx nice tricks ;)

@goshakkk : we have a problem with the core-js library ... $.hide.js:8 Uncaught TypeError: $.setDesc is not a function

$.hide.js

var $          = require('./$')
  , createDesc = require('./$.property-desc');
module.exports = require('./$.descriptors') ? function(object, key, value){
  return $.setDesc(object, key, createDesc(1, value));
} : function(object, key, value){
  object[key] = value;
  return object;
};

vendor.js

require.register("core-js/library/modules/$.js", function(exports, require, module) {
  require = __makeRelativeRequire(require, {}, "core-js");
  (function() {
    var $Object = Object;
module.exports = {
  create:     $Object.create,
  getProto:   $Object.getPrototypeOf,
  isEnum:     {}.propertyIsEnumerable,
  getDesc:    $Object.getOwnPropertyDescriptor,
  setDesc:    $Object.defineProperty,
  setDescs:   $Object.defineProperties,
  getKeys:    $Object.keys,
  getNames:   $Object.getOwnPropertyNames,
  getSymbols: $Object.getOwnPropertySymbols,
  each:       [].forEach
};
  })();
});
require.register("core-js/library/modules/$.hide.js", function(exports, require, module) {
  require = __makeRelativeRequire(require, {}, "core-js");
  (function() {
    var $          = require('./$')
  , createDesc = require('./$.property-desc');
module.exports = require('./$.descriptors') ? function(object, key, value){
  return $.setDesc(object, key, createDesc(1, value));
} : function(object, key, value){
  object[key] = value;
  return object;
};
  })();
});
goshacmd commented 8 years ago

@zecaptus yup, looks like an issue. On it.

goshacmd commented 8 years ago

@zecaptus I've added another commit in https://github.com/brunch/commonjs-require-definition/pull/15 to account for that case.

It's basically happening because we are creating several "layers" of aliases — for example, a.b.c.js is aliased to a.b.c, a.b, and a (this is useful for template files which can have .tmp.hbs or something). However, in this case, it seems to have backfired, because in core-js, the first file with $.<something>.js will alias to $, not $.js.

The fix I've added will basically, if an alias already exists for something, let something.js override it.

zecaptus commented 8 years ago

@goshakkk Nice now all work ;) Thank you