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

Upgrading to latest cli (1.0.0-beta13) throws error loading require local dependency #1054

Closed
salminio opened this Issue Feb 19, 2019 · 6 comments

Comments

Projects
None yet
2 participants
@salminio
Copy link

salminio commented Feb 19, 2019

I'm submitting a bug report

  • Library Version:
    1.0.0-beta13

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    10.0.0

  • NPM Version:
    6.8.0 (initially tried with 5.6.0)

  • Browser:
    Failed on first one tried - Chrome 71.0.3578.98 (Official Build) (64-bit)

  • Language:
    ESNext

  • Loader/bundler:
    RequireJS

Current behavior:
It's failing to load some modules which looks to be because of a local require reference inside a bundled dist AMD built file... I've come across 2. One with aurelia-resize use of element-resize-detector and another is jshint which we actually use at runtime not just development. This works with the amodro tracer used with aureali-cli@0.26.1

Probably the easiest to debug and recreate is the aurelia-resize... The following is included in the vendor bundle and it fails to load.

{
    "name": "aurelia-resize",
    "path": "../node_modules/aurelia-resize/dist/amd",
    "main": "index"
},
{
    "name": "element-resize-detector",
    "path": "../node_modules/element-resize-detector/dist",
    "main": "element-resize-detector"
},

As best I can tell the element-resize-detector is failing on a require statement inside the element-resize-detector.

The following line is throwing the error

//Detection strategies.
var objectStrategyMaker = require('./detection-strategy/object');

With the following stacktrace:

Unhandled rejection Error: Module name "detection-strategy/object" has not been loaded yet for context: _. Use require([])https://requirejs.org/docs/errors.html#notloaded 
 at makeError (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:3834:17) 
 at Object.localRequire [as require] (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:5102:44) 
 at requirejs (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:5463:24) 
 at o (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:56143:561) 
 at http://localhost:9000/scripts/vendor-bundle-8.5.0.js:56143:752 
 at Object.7../browser-detector (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:57242:31) 
 at o (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:56143:701) 
 at r (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:56143:867) 
 at http://localhost:9000/scripts/vendor-bundle-8.5.0.js:56143:896 
 at Object.execCb (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:5362:33) 
 at Module.check (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:4544:55) 
 at Module.enable (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:4842:22) 
 at Object.enable (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:5223:39) 
 at Module. (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:4827:33) 
 at http://localhost:9000/scripts/vendor-bundle-8.5.0.js:3800:23 
 at each (http://localhost:9000/scripts/vendor-bundle-8.5.0.js:3725:31)

JSHint was failing on something similar

var vars         = require("./vars.js");

throws same error.

  • What is the expected behavior?
    Should load and work.

  • What is the motivation / use case for changing the behavior?
    Tech currency... Trying to migrate to latest aurelia and babel 7 code.

huochunpeng added a commit to huochunpeng/resize-demo that referenced this issue Feb 19, 2019

@huochunpeng

This comment has been minimized.

Copy link
Member

huochunpeng commented Feb 19, 2019

There is no issue for me. https://github.com/huochunpeng/resize-demo

You could have some other uncommon setup.

You can try migrate to a clean project created out of au new.
Or you can show me your aurelia.json file.

BTW, it's unnecessary to have the explicit deps config for aurelia-resize and element-resize-detector. Latest cli can work it out automatically.

@salminio

This comment has been minimized.

Copy link
Author

salminio commented Feb 20, 2019

By adding the below to aurelia.json on a newly generated Hello World app... I get it to fail, but if I remove it and let aurelia build it without - then it creates the bundle differently and it works..

                    {
                        "name": "aurelia-resize",
                        "path": "../node_modules/aurelia-resize/dist/amd",
                        "main": "index"
                    },
                    {
                        "name": "element-resize-detector",
                        "path": "../node_modules/element-resize-detector/dist",
                        "main": "element-resize-detector"
                    },
@salminio

This comment has been minimized.

Copy link
Author

salminio commented Feb 20, 2019

I referenced by name only and it works... We break up some 3rd party into different bundles for just in time loading so that is important but the following definition in aurelia.json seems to work

                    "aurelia-resize",
                    "element-resize-detector",

@salminio salminio closed this Feb 20, 2019

@salminio

This comment has been minimized.

Copy link
Author

salminio commented Feb 20, 2019

referencing by name seems to fix both of the issues I had reported

@huochunpeng

This comment has been minimized.

Copy link
Member

huochunpeng commented Feb 20, 2019

The problem is the element-resize-detector dist file.

Without explicit config, element-resize-detector uses main file src/element-resize-detector.js as pointed by package.json main field (very strange, the package.json didn't have a browser field pointing to the dist/element-resize-detector.js). That's why there is no issue when using default auto tracing.

I will have a look what went wrong when tracing dist/element-resize-detector.js.

huochunpeng added a commit to huochunpeng/cli that referenced this issue Feb 20, 2019

fix(bundler): skip deps cleanup (remove .js) for UMD file
When the UMD file was prepared by browserify, those `require('./a.js')` were matched by a hash map like {'./a.js':1}. We cannot clean them up to `require('./a')`, as it will end up with missing entry.

closes aurelia#1054
@huochunpeng

This comment has been minimized.

Copy link
Member

huochunpeng commented Feb 20, 2019

The fix will be in next release.

huochunpeng added a commit to huochunpeng/cli that referenced this issue Feb 20, 2019

fix(bundler): skip deps cleanup (remove .js) for UMD file
When the UMD file was prepared by browserify, those `require('./a.js')` were matched by a hash map like {'./a.js':1}. We cannot clean them up to `require('./a')`, as it will end up with missing entry.

closes aurelia#1054
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.