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

Re-import axios ! #34

Merged
merged 2 commits into from
Nov 28, 2024
Merged

Re-import axios ! #34

merged 2 commits into from
Nov 28, 2024

Conversation

Adesin-fr
Copy link
Contributor

Axios import can't be removed !

If the main project doesn't include project (which can happen, I do !!), then this will fail without axios...

Adesin-fr and others added 2 commits November 28, 2024 09:47
If the caller project doesn't have it as a dependecy, it won't work !
@leob leob merged commit 82243ee into georgeboot:master Nov 28, 2024
1 of 4 checks passed
@leob
Copy link
Collaborator

leob commented Nov 28, 2024

@Adesin-fr Okay I've merged it ... yes in the git history I see that on November 11th you added the Axios import, and then on November 15th I removed it, lol ... why did you add it in the first place (on the 11th) ? Because originally it wasn't there ... but I also don't remember why I removed it again - I hope that adding it back isn't going to cause issues ;-)

Anyway, I'm going to test and debug this (I'll probably add more logging in a few places, also in the PHP code) ...

Just a silly question:

In order to test/debug this I'm increasing the version number, make a release, deploy it to npmjs, then build and deploy our app to AWS, etc - and only then can I start testing/debugging it - and if it doesn't work and I need to make changes, then I need to go through this whole long-winded process again - isn't there a way to simplify this and to speed this up?

Maybe just point to a "local" version in my package.json and/or composer.json, I've done something like that before - that still leaves the lengthy AWS deploy from our app, but at least we don't need to go through a full "publish" ... tips, ideas, thoughts?

P.S. ah, look what I have now - one of the Github CI jobs (ESLint) is now failing - for sure that's the reason why I removed the Axios import, because I'm now getting a mountain of errors, see screenshot below

image

See details here: https://github.com/georgeboot/laravel-echo-api-gateway/actions/runs/12067411745/job/33650302647

This is now failing ... thoughts? Can't we get rid of the import again - can't you add the dependency to your app? Previously the import was NOT there - if it's not necessary then I would prefer not to have it ...

@Adesin-fr
Copy link
Contributor Author

Yes you can reference your local npm package in your target env .
in your package.json file, just set "file:path to your local repo" instead of the npm version number.
Don't forget to rebuild your npm local repo everytime you make a change !

@leob
Copy link
Collaborator

leob commented Nov 28, 2024

Yes you can reference your local npm package in your target env . in your package.json file, just set "file:path to your local repo" instead of the npm version number. Don't forget to rebuild your npm local repo everytime you make a change !

@Adesin-fr Thanks, yes I've done something like that previously, either with npm or with composer or both - I don't remember the details of how to do it, but I'll figure it out ...

But, we now have a build error, see previous comment - for sure that's the reason why I removed that Axios import (which we previously didn't have ...)

@leob
Copy link
Collaborator

leob commented Nov 29, 2024

@Adesin-fr What shall we do with this - do you think it's possible to get rid of the build error, or shall we remove the import again and you add the dependency to your app's package.json?

@Adesin-fr
Copy link
Contributor Author

That's not a good thing to depend on caller's dependencies !
I'll git it a look quickly ;)

@leob
Copy link
Collaborator

leob commented Nov 29, 2024

That's not a good thing to depend on caller's dependencies ! I'll git it a look quickly ;)

@Adesin-fr I understand what you say, but the import wasn't there to begin with ... yes please have a look :)

@leob
Copy link
Collaborator

leob commented Nov 30, 2024

@Adesin-fr Okay, I really have my doubts if this it's wisdom to push on with this "import axios" thing, but with a lot of trial and error I MIGHT have got it working ...

First, I did a local yarn install (or npm install), and I got this error:

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
axios (imported by js-src/Websocket.ts)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
axios (guessing 'axios')

I then looked up https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency and here's what it says:

_Warning: "Treating [module] as external dependency"
Rollup will only resolve relative module IDs by default. This means that an import statement like this…

import moment from 'moment';

…won't result in moment being included in your bundle – instead, it will be an external dependency that is required at runtime.

If you do want to include the module in your bundle, you need to tell Rollup how to find it. In most cases, this is a question of using @rollup/plugin-node-resolve._

So I then went down into a rabbit hole involving "rollup" and "rollup plugins" and so on (all of which I never heard about before), and then I came across this link:

https://limistah.dev/posts/configure-axios-rollup/

So I went ahead and did what this article says, and added those "rollup plugins" and a piece of "rollup config" ... and then it still didn't work ;-)

I then came across this one:

axios/axios#1259 (comment)

so I then got rid of the other 2 "plugins" and switched to the "common JS" one - and then it STILL didn't work ... but, when I threw all 3 plugins in, and their pieces of config, THEN node install completed without errors!

To me it feels I have no clue what I'm doing, and I'm just googling and doing "trial and error", but somehow this seems to at least build ... but another story is whether it will also WORK.

I'll create a PR for you with the stuff I cobbled together and you can test if that works - but, right now I'm going to delete that import statement from master, and I'm going to focus on getting the changes from PR 33 working with our app - and once that works, we can try to get the "import axios" thing to work (using the new PR).

P.S. what also irks me enormously is the hassle with yarn versus npm - I'm all the time switching between the two because yarn is frequently throwing up on me - like I said above, I had a successful build with npm install, but when I do yarn install I'm still getting an error:

laravel-echo-api-gateway/js-src/Connector.ts(5,64): semantic error TS2351: This expression is not constructable.
  Type 'typeof Connector' has no construct signatures.
    at error (laravel-echo-api-gateway/node_modules/rollup/dist/shared/rollup.js:198:30)

No idea what this is, and only "yarn" complains about it ... I'm also getting this on a frequent basis:

error SyntaxError: Invalid value type 1135:0 in laravel-echo-api-gateway/yarn.lock

Solution is to delete the yarn.lock file and rerun the command but at some point it will come back ...

Not to mention the fact that we now have yarn.lock AND a package.lock - which I don't want either, but yeah ... ultimate chaos - I'd really love to get rid of yarn and just use npm !

@leob
Copy link
Collaborator

leob commented Nov 30, 2024

@Adesin-fr I've deleted the import axios for now (in master), but I've created a PR which we can use to reintroduce it, please have a look:

#35

I see that it triggers a bunch of failed Github CI jobs, so I think this needs extra work (but I'm mainly blaming "yarn" for that), but I'm now going to focus on getting the functionality of PR 33 working with our app, I'll leave PR 35 to you ...

@Adesin-fr
Copy link
Contributor Author

I have something that seems to compile and work with axios.
I'll try to make a PR into the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants