ember-cli / ember-fetch

HTML5 fetch polyfill from github wrapped and bundled for ember-cli users.
MIT License
175 stars 79 forks source link

Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch` #166

Closed lougreenwood closed 5 years ago

lougreenwood commented 5 years ago

Hello, I'm getting the following build error on my CI server. Downgrading to 5.1 (before /instance-initializers/setup-fetch was introduced) fixes the issue.

Build Error (prember)

Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`

=================================================================================

ENV Summary:

  TIME: Sat Nov 17 2018 19:26:34 GMT+0000 (UTC)
  TITLE: ember
  ARGV:
  - /usr/bin/node
  - /usr/local/bin/ember
  - b
  - -prod
  EXEC_PATH: /usr/bin/node
  TMPDIR: /tmp
  SHELL: /bin/ash
  PATH:
  - /usr/local/sbin
  - /usr/local/bin
  - /usr/sbin
  - /usr/bin
  - /sbin
  - /bin
  PLATFORM: linux x64
  FREEMEM: 9050533888
  TOTALMEM: 73765941248
  UPTIME: 78321
  LOADAVG: 8.33837890625,5.37841796875,3.8583984375
  CPUS:
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  - Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz - 3000
  ENDIANNESS: LE
  VERSIONS:
  - ares: 1.14.0
  - cldr: 32.0
  - http_parser: 2.8.1
  - icu: 60.1
  - modules: 57
  - napi: 3
  - nghttp2: 1.32.0
  - node: 8.11.4
  - openssl: 1.0.2o
  - tz: 2017c
  - unicode: 10.0
  - uv: 1.20.2
  - v8: 6.2.414.54
  - zlib: 1.2.11

ERROR Summary:

  - broccoliBuilderErrorStack: Error: Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`
    at /tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11:31
    at l (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11:96)
    at a.findDeps (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:23:158)
    at l (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11:152)
    at requireModule (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:5:60)
    at t (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11178:21)
    at /tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11182:233
    at e.default (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11182:242)
    at a.callback (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/prog.js:585:145)
    at a.exports (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:18:21)
    at a._reify (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:21:35)
    at a.reify (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:20:23)
    at a.exports (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:17:84)
    at Object.requireModule (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:5:106)
    at Object.<anonymous> (/src/prog/node_modules/fastboot/src/ember-app.js:179:18)
    at VMSandbox.run (/src/prog/node_modules/fastboot/src/vm-sandbox.js:18:15)
    at EmberApp.createEmberApp (/src/prog/node_modules/fastboot/src/ember-app.js:178:30)
    at EmberApp.retrieveSandboxedApp (/src/prog/node_modules/fastboot/src/ember-app.js:203:17)
    at new EmberApp (/src/prog/node_modules/fastboot/src/ember-app.js:59:21)
    at FastBoot._buildEmberApp (/src/prog/node_modules/fastboot/src/index.js:114:17)
    at new FastBoot (/src/prog/node_modules/fastboot/src/index.js:52:10)
    at Prerender.build (/src/prog/node_modules/prember/lib/prerender.js:83:15)
    at <anonymous>
  - codeFrame: Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`
  - errorMessage: Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`
        at prember
-~- created here: -~-
    at new Plugin (/src/prog/node_modules/broccoli-plugin/index.js:7:31)
    at new Prerender (/src/prog/node_modules/prember/lib/prerender.js:19:5)
    at Class.postprocessTree (/src/prog/node_modules/prember/index.js:25:9)
    at projectOrAddon.addons.reduce (/src/prog/node_modules/ember-cli/lib/utilities/addon-process-tree.js:6:25)
    at Array.reduce (<anonymous>)
    at addonProcessTree (/src/prog/node_modules/ember-cli/lib/utilities/addon-process-tree.js:4:32)
    at EmberApp.addonPostprocessTree (/src/prog/node_modules/ember-cli/lib/broccoli/ember-app.js:843:12)
    at EmberApp.host.addonPostprocessTree (/src/prog/node_modules/ember-auto-import/js/auto-import.js:94:20)
    at EmberApp.toTree (/src/prog/node_modules/ember-cli/lib/broccoli/ember-app.js:1772:17)
    at module.exports (/src/prog/ember-cli-build.js:100:16)
-~- (end) -~-
  - errorType: Build Error
  - location:
    - column: [undefined]
    - file: [undefined]
    - line: [undefined]
    - treeDir: [undefined]
  - message: Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`
        at prember
-~- created here: -~-
    at new Plugin (/src/prog/node_modules/broccoli-plugin/index.js:7:31)
    at new Prerender (/src/prog/node_modules/prember/lib/prerender.js:19:5)
    at Class.postprocessTree (/src/prog/node_modules/prember/index.js:25:9)
    at projectOrAddon.addons.reduce (/src/prog/node_modules/ember-cli/lib/utilities/addon-process-tree.js:6:25)
    at Array.reduce (<anonymous>)
    at addonProcessTree (/src/prog/node_modules/ember-cli/lib/utilities/addon-process-tree.js:4:32)
    at EmberApp.addonPostprocessTree (/src/prog/node_modules/ember-cli/lib/broccoli/ember-app.js:843:12)
    at EmberApp.host.addonPostprocessTree (/src/prog/node_modules/ember-auto-import/js/auto-import.js:94:20)
    at EmberApp.toTree (/src/prog/node_modules/ember-cli/lib/broccoli/ember-app.js:1772:17)
    at module.exports (/src/prog/ember-cli-build.js:100:16)
-~- (end) -~-
  - name: BuildError
  - nodeAnnotation: [undefined]
  - nodeName: prember
  - originalErrorMessage: Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`
  - stack: Error: Could not find module `fetch/setup` imported from `prog/instance-initializers/setup-fetch`
    at /tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11:31
    at l (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11:96)
    at a.findDeps (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:23:158)
    at l (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11:152)
    at requireModule (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:5:60)
    at t (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11178:21)
    at /tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11182:233
    at e.default (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:11182:242)
    at a.callback (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/prog.js:585:145)
    at a.exports (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:18:21)
    at a._reify (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:21:35)
    at a.reify (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:20:23)
    at a.exports (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:17:84)
    at Object.requireModule (/tmp/broccoli-206JY0r2WxIPHx0/out-908-uglify_writer/assets/vendor.js:5:106)
    at Object.<anonymous> (/src/prog/node_modules/fastboot/src/ember-app.js:179:18)
    at VMSandbox.run (/src/prog/node_modules/fastboot/src/vm-sandbox.js:18:15)
    at EmberApp.createEmberApp (/src/prog/node_modules/fastboot/src/ember-app.js:178:30)
    at EmberApp.retrieveSandboxedApp (/src/prog/node_modules/fastboot/src/ember-app.js:203:17)
    at new EmberApp (/src/prog/node_modules/fastboot/src/ember-app.js:59:21)
    at FastBoot._buildEmberApp (/src/prog/node_modules/fastboot/src/index.js:114:17)
    at new FastBoot (/src/prog/node_modules/fastboot/src/index.js:52:10)
    at Prerender.build (/src/prog/node_modules/prember/lib/prerender.js:83:15)
    at <anonymous>

=================================================================================

Exited with code 1
xg-wang commented 5 years ago

Hi @lougreenwood what is your Pember and fastboot version? Can you also take a look at https://github.com/shipshapecode/shipshape.io as mentioned in https://github.com/ember-cli/ember-fetch/pull/143#issuecomment-438046353 to see what's the difference?

davidbilling commented 5 years ago

@xg-wang I get the same error, I do not use Prember only fastboot 2.0.0.

xg-wang commented 5 years ago

@davidbilling Were you trying to make a fetch before the instance initializer?

davidbilling commented 5 years ago

@xg-wang Not sure of the run-loop scoop of instance initialazer. My first fetch is directly when the page is loaded though. But I have not made any own instance initialaziers.

lougreenwood commented 5 years ago

hey @xg-wang - I'm using:

xg-wang commented 5 years ago

@lougreenwood @davidbilling Do you have reproduction steps?

lougreenwood commented 5 years ago

For me, this happens when doing an ember b -prod. I was already using ember-fetch in this codebase and downgrading back to 5.1 fixes the issue.

As a side note, 6.2 works fine in the same codebase with ember s - for me, it's only at build time where the problem appears.

I'm also using ember-auto-import v1.2.13, if that's of any use.

xg-wang commented 5 years ago

@lougreenwood Does 6.1.1 has same issue?

xg-wang commented 5 years ago

Pretty sure it’s some of the app’s dependency has a ember-fetch with different version and public/fastboot-fetch.js got overwritten

lougreenwood commented 5 years ago

@xg-wang I think you're right, seems that the problem is ember-simple-auth - adding this to package.json seems to solve it for me:

  "resolutions": {
    "ember-simple-auth/**/ember-fetch": "^6.2.0"
  }
davidbilling commented 5 years ago

@xg-wang @lougreenwood "resolutions" did not work for me. But I also have "ember-power-select" that uses ember-fetch 3.4.5 and other addons with ember-fetch. I will try to make a better test when I got more time.

samselikoff commented 5 years ago

I'm also getting this error, via the ember-cli-fastboot-testing library.

To reproduce:

ember new my-app

ember install ember-cli-fastboot
ember s  # works

ember install ember-cli-fastboot-testing
ember s 
> Error: Could not find module `fetch/setup` imported from `my-app/instance-initializers/setup-fetch`

I think ember-cli-fastboot-testing has the only dependency on ember-fetch so I'm not sure anything's getting overwritten. How would I go about finding that out?

balinterdi commented 5 years ago

I also got this error and I think that's because you have an instance initializer that calls fetch before fetch could be set up.

In my case, I called the current-user service which imported fetch from an instance initializer. So you have to make sure your instance initializer comes after the fetch one, but only in Fastboot mode.

Here's the fix that worked for me:

// app/instance-initializers/current-user.js

 export function initialize(appInstance) {
  let session = appInstance.lookup('service:session');
  let currentUser = appInstance.lookup('service:current-user');
  session.on('authenticationSucceeded', function() {
    currentUser.load();
  });
  session.on('invalidationSucceeded', function() {
    currentUser.unload();
  });
}

const exportObject = {
  initialize
}

if (typeof FastBoot !== 'undefined') {
  exportObject.after = 'fetch';
}

export default exportObject;
willviles commented 5 years ago

I've installed from @xg-wang's https://github.com/ember-cli/ember-fetch/pull/167 PR commit and my builds are now succeeding ✅

"ember-fetch": "git+https://github.com/xg-wang/ember-fetch.git#a98c1b2a0b706cd8e663c90b631785ea49e08de7",

Hopefully https://github.com/ember-cli/ember-fetch/pull/167 can be merged in soon 👍

xg-wang commented 5 years ago

Released as v6.2.3. Feel free to reopen if this is still an issue.

balinterdi commented 5 years ago

This release introduced a regression in my app. The following code works in v6.2.2 but breaks in v6.2.3:

// app/instance-initializers/current-user.js
 export function initialize(appInstance) {
  let session = appInstance.lookup('service:session');
  let currentUser = appInstance.lookup('service:current-user');
  session.on('authenticationSucceeded', function() {
    currentUser.load();
  });
  session.on('invalidationSucceeded', function() {
    currentUser.unload();
  });
}

const exportObject = {
  initialize
}

if (typeof FastBoot !== 'undefined') {
  exportObject.after = 'fetch';
}

export default exportObject;

(currentUser.load calls fetch)

The error I get is

Error: Could not find module fetch/setup imported from rarwe/instance-initializers/setup-fetch

Am I doing something wrong?

xg-wang commented 5 years ago

@balinterdi 🤔 fetch/setup has been removed in v6.2.3 it shouldn't be invoked. https://github.com/ember-cli/ember-fetch/compare/v6.2.2...v6.2.3#diff-2992dd665823759d28df78b0c59aff62L1

lougreenwood commented 5 years ago

@balinterdi

I think I same the same issue when I upgraded to 6.3.0, it was the same incompatibility with ember-simple-auth's dependency on ember-fetch 5.x which I previously patched with a fork.

IIRC, adding this to package.json resolutions fixed it for me:

"resolutions": {
        "ember-simple-auth/**/ember-fetch": "^6.3.0"
}
balinterdi commented 5 years ago

@xg-wang I didn't invoke fetch/setup directly from my code, not sure what did it. Anyway, I've now tested again with both version 6.3.1 and 6.2.3 and it worked fine in both cases – and without the need for the above hack (where I check in the instance-initializer if we're in Fastboot mode) or the resolution @lougreenwood mentioned.

@lougreenwood ember-simple-auth extended the range of acceptable ember-fetch versions in this commit, did you try and see if you need the explicit resolution with ESA master?

lougreenwood commented 5 years ago

@balinterdi sure did, I actually submitted a PR before this commit - I was using my fork for my PR: https://github.com/simplabs/ember-simple-auth/pull/1716

Not sure why my fork stopped working but resolutions fixed it for me

xg-wang commented 5 years ago

@balinterdi Do you think it could be node_modules cache issue? Seems you don't see it anymore when you test it again.

balinterdi commented 5 years ago

@xg-wang Sorry, I no longer remember exactly what I did so that it started working. I don't recall doing anything in particular but it's possible that I removed node_modules and ran yarn again.