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

[beta1.3] ESM support #179

Open
ironkayman opened this issue Aug 4, 2022 · 3 comments
Open

[beta1.3] ESM support #179

ironkayman opened this issue Aug 4, 2022 · 3 comments

Comments

@ironkayman
Copy link

Same case as in #95, but for beta1.3. Also it may be considered a continuation of #178

Hello! I'm using ES modules in a project, so, i installed TKO build reference from the npm registry 4.0.0-beta1.3

package.json

"dependencies": {
    "@tko/build.reference": "^4.0.0-beta1.3"
  },

and then calling npm i i'm getting following error:

output

node_modules/@tko/build.reference/dist/index.js:2:24: Cannot resolve dependency '@tko/builder'
  1 | // @tko/build.reference 🥊 4.0.0-beta1.3 ESM
> 2 | import { Builder } from "@tko/builder";

code

import ko from "@tko/build.reference/dist/index"
# the default export from build.reference is actualy a knockout instance from Builder.create(...)

that same issue of abscent @tko/builder i encountered while building TKO myself from same git tag with make and esbuild. What i got:

  • esbuild successfully populated builds/reference/dist
  • trying to import either reference/index.ts and/or reference/dist/index.js still getting same error above.

Right now i'm stumped, i may look into builder, and build.reference dependencies. Can there be a case of some sorts of recursive modules installation? Any advice will be greatly appreciated. Thank you!

@brianmhunt
Copy link
Member

@ironkayman Thanks for noting.This is odd, and seem to work fine in the ordinary case e.g. a blank project

CleanShot 2022-08-04 at 08 11 13@2x

I'm using the latest esbuild for @tko generally, so it should be working fine.

A support forum like StackOverflow may be able to offer better/further guidance, too.

Sorry I don't have more helpful guidance to offer - please share any other details you think might be relevant.

@ironkayman
Copy link
Author

ironkayman commented Aug 6, 2022

@brianmhunt Apologies for radiosilence. Firstly, thank you for your concerns!

TLDR: i were using parcel 1 for bundling and watching changes with it in my test project - switching to esbuild + ESM TKO build fixed the issue without further complications.

Basically:
Parcel (v1, i did not test v2, didnt really looked into its issues) somewhy was ignoring default ESM export in case of TKO (the ko instance from Builder.create was created successfully, to be precise, but external import in my project directory was failing, returning undefined), same issue with IIFE, which worked partially, but failed to addup registered bindings to tko global scope.

Regarding the npm behavior at question, it probably was caused by applying parcel bundling, i still may not fully understand why:
running npm install after first parcel build is the possible cause of the issue, as only after that the instllation of @tko/build.reference started to fail. Or, it may be both issues in parcel (considering its no longer maintained version). To recreate, enought to apply parcel-bundler 'watch' configuration on very basic TKO project from 1 component at least (as its what i were testing on).

Also while at it, from my experience and experience of my colleagues with TKO as a newcomers (we're in a process of migration from ko 3.5.1 to current TKO), i strongly believe the project readme may be, can be and should be presented/structured more approachable, as at least (imho) it should be updated for beta builds in more details, be more self-sustaining as it is "just enough" for user not to go to wiki/further documentaion offsite (your's prototype or tko.io, very usefull btw)/deeper into the project MDs or source in some (more often than i'd like to admit) cases... and have at least some basic within-arm's-reach examples, i understand as it becomes bigger but i dont see an issue with that. What are your thoughts on it, may i open up a PR in a coming week with an issue here? Sorry if i came off as too rigorous.

Thank you sincerely for your time.

@mattlacey
Copy link

FWIW I put together a light-weight template some time back that uses TKO with webpack and esm: https://github.com/mattlacey/tko_webpack

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 a pull request may close this issue.

3 participants