Skip to content

FastBoot.require is broken when running locallyΒ #221

@bobisjan

Description

@bobisjan

The following error occurs with ember-fetch installed:

Error: Cannot find module 'abortcontroller-polyfill/dist/cjs-ponyfill' from '/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees'
    at Function.module.exports [as sync] (/Users/bobisjan/Developer/fastboot-require-bug/node_modules/resolve/lib/sync.js:58:15)
    at Object.require (/Users/bobisjan/Developer/fastboot-require-bug/node_modules/fastboot/src/ember-app.js:139:42)
    at Module.callback (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/ember-fetch/fetch-fastboot.js:6:42)
    at Module.exports (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/vendor/loader/loader.js:106:1)
    at requireModule (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/vendor/loader/loader.js:27:1)
    at r (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/vendor/loader/loader.js:176:1)
    at Module.callback (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/addon-tree-output/ember-data/-private.js:14244:1)
    at Module.exports (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/vendor/loader/loader.js:106:1)
    at Module._reify (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/vendor/loader/loader.js:143:1)
    at Module.reify (/var/folders/m3/2d92q9yx06j2q51zh2_w8js80000gn/T/broccoli-76884UZpwDvEhdhpO/out-206-broccoli_merge_trees/assets/vendor/loader/loader.js:130:1)

The problem is that resolve.sync can not find module based on the basedir set to distPath https://github.com/ember-fastboot/fastboot/blob/master/src/ember-app.js#L139.

This does not occur in previous version (1.x), because of this fallback https://github.com/ember-fastboot/fastboot/blob/master/src/ember-app.js#L151, I assume that this works only by accident, because that branch was meant (based on the comment) only for Node.js internal modules like path, os, ...

The "production" usage with fastboot-app-server is not affected, because it requires to run npm install in "dist" directory (manually http://ember-fastboot.com/docs/deploying#deploying-your-app or automatically eq. when using S3 downloader https://github.com/ember-fastboot/fastboot-s3-downloader/blob/master/index.js#L110), hence the resolve.sync works fine.

Possible quick fixes

Remove the basedir option from resolve.sync call.

or

Run npm install inside distPath after build from ember-cli-fastboot add-on.

Proper fix

Deprecate FastBoot.require for importing external modules (only internals are allowed like path, os, ...) and use ember-auto-import add-on.

What do you think? @kratiahuja, @rwjblue, @xg-wang

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions