Code Monkey home page Code Monkey logo

Comments (28)

mhluska avatar mhluska commented on July 16, 2024 5

I ended up getting this working by doing npm install --save abortcontroller-polyfill in my fastboot repo. It's not great but a temporary workaround that lets me deploy again until this is fixed.

from ember-fetch.

mike-north avatar mike-north commented on July 16, 2024 2

I just ran into this problem and found the root cause.

#112 introduced the use of the abortcontroller-polyfill library
#113 included the appropriate module in fastbootDependencies so that consuming apps shouldn't have to do anything

The first release this stuff went out in was v5.0.0


To reproduce the problem, you need to have conflicting versions of ember-fetch. I've forked @Mciocca's repo and made a small change which should make this reproducable for everyone.

Here's how we know we're in the problematic situation

$ yarn why ember-fetch
=> Found "[email protected]"
=> Found "ember-simple-auth#[email protected]"
✨  Done in 1.08s.

Now when you start the example and navigate to /google, you should see

the error message.
Error: Unable to require module 'abortcontroller-polyfill/dist/cjs-ponyfill' because it was not in the whitelist.
    at Object.require (/Users/mnorth/Development/fastboot-test/node_modules/fastboot/src/ember-app.js:133:15)
    at Module.callback (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/ember-fetch/fastboot-fetch.js:4:44)
    at Module.exports (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/vendor/loader/loader.js:106:1)
    at Module._reify (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/vendor/loader/loader.js:143:1)
    at Module.reify (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/vendor/loader/loader.js:130:1)
    at Module.exports (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/vendor/loader/loader.js:104:1)
    at requireModule (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/vendor/loader/loader.js:27:1)
    at Class._extractDefaultExport (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/addon-tree-output/ember-resolver/resolvers/classic/index.js:410:1)
    at Class.resolveOther (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/addon-tree-output/ember-resolver/resolvers/classic/index.js:110:1)
    at Class.superWrapper (/Users/mnorth/Development/fastboot-test/tmp/broccoli_merge_trees-output_path-5c3odJR1.tmp/assets/ember-utils.js:428:1)

What appears to be happenning here is a ember-fetch@5 is doing the stuff introduced by #112, but because a ember-fetch@3 is a the top-level dependency, the fix in #113 is not picked up. The end result is that a non-whitelisted module is required and the error is thrown

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024 1

So I played around with it and had these results:

Fastboot is require'ing from <your-app>/dist/node_modules/<module-name>, but the node_modules are not actually bundled into dist, they are at <your-app>/node_modules/<module-name> instead. The above case results in existsSync check fails for both node-fetch and abortcontroller-polyfill/dist/cjs-ponyfill in this test.

When the check fails, Fastboot does require('abortcontroller-polyfill/dist/cjs-ponyfill')

  • This succeeds when you serve express server from project root
  • But it FAILs when you serve from anothe location

Then I changed to the actual path let nodeModulesPath = path.join(distPath, '..', 'node_modules', moduleName);src.
Now require('<absolute-path-to>node-fetch') succeeds but require('<absolute-path-to>abortcontroller-polyfill/dist/cjs-ponyfill') fails.
I have to do require('absolute-path-to>abortcontroller-polyfill/dist/cjs-ponyfill.js') and it will work.


Conclusion:

  • To fix it @Mciocca can do node server.js from fastboot-test/
  • There's a <bug?> in Fastboot to read the node_modules
  • ember-fetch should require .js file here and announce fastboot dep as .js. I need to check node's documentation about this.

from ember-fetch.

davidbilling avatar davidbilling commented on July 16, 2024 1

@Mciocca I use fastboot-aws and used above fix and installed the abortcontroller-polyfill in the fastboot-aws repro. That works for now.

from ember-fetch.

allthesignals avatar allthesignals commented on July 16, 2024 1

I'm seeing this issue as well in spite of upgrading. Should it be closed?

After using @mhluska's fix, I am seeing this:
Error: Cannot find module 'node-fetch'

from ember-fetch.

Turbo87 avatar Turbo87 commented on July 16, 2024

/cc @tchak @stefanpenner

from ember-fetch.

tchak avatar tchak commented on July 16, 2024

It looks like fasboot node packages are not properly installed...

from ember-fetch.

Mciocca avatar Mciocca commented on July 16, 2024

@tchak
I followed the instructions on the fastboot website. Where did I go wrong?
It could very well have been a mistake on my end or something not well documented.

from ember-fetch.

tchak avatar tchak commented on July 16, 2024

@Mciocca I just tried your demo app and it works for me... Can I see your server.js file?

from ember-fetch.

Mciocca avatar Mciocca commented on July 16, 2024

@tchak Pretty much just copy and pasted from the fastboot-app-server repo

const FastBootAppServer = require('fastboot-app-server');

const MY_GLOBAL = 'MY GLOBAL';

let server = new FastBootAppServer({
  distPath: '/Users/mciocca/fb-test/dist',
  gzip: true, // Optional - Enables gzip compression.
  host: '0.0.0.0', // Optional - Sets the host the server listens on.
  port: 4000, // Optional - Sets the port the server listens on (defaults to the PORT env var or 3000).
  sandboxGlobals: { GLOBAL_VALUE: MY_GLOBAL }, // Optional - Make values available to the Ember app running in the FastBoot server, e.g. "MY_GLOBAL" will be available as "GLOBAL_VALUE"
  chunkedResponse: true // Optional - Opt-in to chunked transfer encoding, transferring the head, body and potential shoeboxes in separate chunks. Chunked transfer encoding should have a positive effect in particular when the app transfers a lot of data in the shoebox.
});

server.start();

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

Are you running server.js from another location other than fastboot-test/?
I notice you're using distPath: '/Users/mciocca/fb-test/dist', and the example is distPath: 'dist',.

If you are running server.js from another location without node_modules having your dependencies the error would be thrown.

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

/cc @thoov
About the node_modules were missing in dist, I remember you were doing something related?

from ember-fetch.

mhluska avatar mhluska commented on July 16, 2024

@xg-wang so what's the fix here? I'm already running node server.js in the project root. I tried rolling back ember-fetch from v5 to v4 with no improvement. I also tried appending .js to the require but the error persists.

from ember-fetch.

kratiahuja avatar kratiahuja commented on July 16, 2024

@xg-wang you shouldn't ideally need node_modules in dist if you don't have any whitelisted packages.

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

@kratiahuja abortcontroller-polyfill and node-fetch are whitelisted by ember-fetch, and should be abled to be required in Fastboot.

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

@mhluska mind sharing a reproduction? I have @Mciocca 's example repo working by doing node server.js from fastboot-test/

from ember-fetch.

The-Don-Himself avatar The-Don-Himself commented on July 16, 2024

Just wanted to add that I ran into this issue today after deploying a long overdue update. There were so many package upgrades to remember what exactly changed. @mhluska fix does it for me.

from ember-fetch.

afuno avatar afuno commented on July 16, 2024

Well, so in the end? How to solve this problem? Above in your answers, I saw nothing.

from ember-fetch.

davidgovea avatar davidgovea commented on July 16, 2024

After building, our app's "fastboot dist" package.json has abortcontroller-polyfill and node-fetch whitelisted, but only node-fetch is included in the dependencies.

For now, we've installed abortcontroller-polyfill at the fastboot server level, as @mhluska suggested.

from ember-fetch.

davidbilling avatar davidbilling commented on July 16, 2024

I have the same problem, is there a way to contribute to a solution? This is a showstopper for my production... (I don't know that much about fastboot, yet)

from ember-fetch.

Mciocca avatar Mciocca commented on July 16, 2024

@davidbilling A temporary fix is to just keep your fastboot server in the root of your ember app's directory. It's not great to not be able to separate your ember app from your fastboot app server, but it works.

from ember-fetch.

jurecuhalev avatar jurecuhalev commented on July 16, 2024

When hitting this error today, installing npm install fastboot-app-server abortcontroller-polyfill in a parent folder from dist, fixed the problem for me.

(installing abortcontroller-polyfill globally, didn't help)

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

@mike-north It seems to be a different issue. I can reproduce @Mciocca 's issue with the non-root server.js. You can compare the error message to confirm.

Actually if you open the file at Object.require (/Users/user/node_modules/fastboot/src/ember-app.js:130:18) It points to the dist/node_modules/<package> not found case.

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

I did more debug.
The reason I have to do require('absolute-path-to>abortcontroller-polyfill/dist/cjs-ponyfill.js') rather than require('<absolute-path-to>abortcontroller-polyfill/dist/cjs-ponyfill') is that the exists-sync Fastboot uses is same thing to fs.existsSync(). The file is ponyfill.js so ponyfill wouldn't exist, but we can actually require it.

I think it's perfectly fine for ember-fetch to require abortcontroller-polyfill/dist/cjs-ponyfill and it's Fastboot's responsibility to require from the correct location for the module (rather than file).
I'll create an issue in Fastboot repo.
@kratiahuja @mike-north

from ember-fetch.

xg-wang avatar xg-wang commented on July 16, 2024

@Mciocca I modified your repro a bit and added some more description here https://github.com/xg-wang/fastboot-issue.

from ember-fetch.

Duder-onomy avatar Duder-onomy commented on July 16, 2024

@mhluska 's fix worked for me.

from ember-fetch.

snewcomer avatar snewcomer commented on July 16, 2024

Ref ember-fastboot/fastboot#227

from ember-fetch.

devotox avatar devotox commented on July 16, 2024

I have found if you just install ember-fetch on the encapsulating server this works without the need to install all packages in the dist directory

from ember-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.