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

Programmatic use not working #87

Closed
Papooch opened this issue Mar 1, 2024 · 5 comments
Closed

Programmatic use not working #87

Papooch opened this issue Mar 1, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Papooch
Copy link

Papooch commented Mar 1, 2024

Describe the bug
When trying to import boats programmatically, I get the following error:

Error: Cannot find module '<path-to-repo>/node_modules/boats/src/index.js'. Please verify that the package.json has a valid "main" entry

To Reproduce
include import boats from 'boats' (or the CJS equivalent) in a source file and run it.

Expected behavior
As per the docs

You can also use BOATS programmatically, just require (import if you are using a bundler) the lib into your project.

I would expect this to work and provide some programmatic API.

@Papooch Papooch added the bug Something isn't working label Mar 1, 2024
@j-d-carmichael
Copy link
Owner

Hi,

Could you show some code of how you're importing?

Thanks,
John

@p-mcgowan
Copy link
Contributor

the issue is main in package.json doesn't point to build/src but src, which doesn't exist after an install.

steps to repro

mkdir test
cd test
npm init --yes
npm i boats
node -p 'require("boats")'

@p-mcgowan
Copy link
Contributor

although that won't fix it anyway - it looks like the index exports the default key from 4 files, so it won't work anyway.

You would have to do something like require('boats/build/src/Template').default in order to use those files

@j-d-carmichael
Copy link
Owner

Dang!

I'm pretty slammed at the moment so not sure i have the time until next month... PR would be very welcomed :)

@j-d-carmichael
Copy link
Owner

@Papooch I've decided as I don't have time to work on this feature to instead remove programmatic use.

If you would like to expose boats in a programmatic way a PR would be welcomed.

The section of boats to expose would be:
https://github.com/j-d-carmichael/boats/blob/main/src/cli.ts#L55
to
https://github.com/j-d-carmichael/boats/blob/main/src/cli.ts#L77

Ideally, the cli.ts file would call a new function or class named "boats" and the package.json would both export the types and the said file.

I would imagine something like added to the package json file:

  "main": "build/src/boats.js",
  "typings": "build/src/boats.d.ts",

For now though, there is no longer an export and I will close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants