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

Preparing Project as NPM Package #23

Merged
merged 7 commits into from
Jul 1, 2024
Merged

Preparing Project as NPM Package #23

merged 7 commits into from
Jul 1, 2024

Conversation

bh2smith
Copy link
Collaborator

@bh2smith bh2smith commented Jul 1, 2024

Preparing this code to be an NPM package.

  • we add tsconfig with a bunch of standard stuff (I barely understand how to choose some of these options).
  • make index an export file
  • move the former main script to examples and
  • update the package json accordingly.

Issues Encountered:

Many Issues were encountered. Mostly involving CommonJS, ESModules and our dependency near-ca (which has since been updated to support both). We also had painful problems with ts-node and now use tsx instead (it is wonderful 🥇 )

Further Details on Issues (all resolved) 1. With `$ ts-node-esm examples/send-tx.ts` ``` TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /mintbase/near-safe/examples/send-tx.ts at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9) at defaultGetFormat (node:internal/modules/esm/get_format:203:36) at defaultLoad (node:internal/modules/esm/load:143:22) at async nextLoad (node:internal/modules/esm/hooks:866:22) at async nextLoad (node:internal/modules/esm/hooks:866:22) at async Hooks.load (node:internal/modules/esm/hooks:449:20) at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18) { code: 'ERR_UNKNOWN_FILE_EXTENSION' ```
  1. With ts-node examples/send-tx.ts
(node:21516) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/mintbase/near-safe/examples/send-tx.ts:1
import dotenv from "dotenv";
^^^^^^

SyntaxError: Cannot use import statement outside a module
  1. Attempting to add "type": "module", to package:
  • Lands us back at Error 1.
  • Also breaking the linter with:
Oops! Something went wrong! :(

ESLint: 9.6.0

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/mintbase/near-safe/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extensio

FML

Test Plan

CI checks install, lint and build

Additional e2e test is yarn example (the old index.ts file).

@bh2smith bh2smith changed the title [WIP] Add TSConfig Preparing Project as NPM Package Jul 1, 2024
@bh2smith bh2smith marked this pull request as ready for review July 1, 2024 13:12
@bh2smith bh2smith merged commit 4e68981 into main Jul 1, 2024
1 check passed
@bh2smith bh2smith deleted the as-lib branch July 1, 2024 13:13
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.

1 participant