Open zacharytyhacz opened 3 months ago
No idea, but i think it's because the package is only exported as esm
Hmm. I'm unable to recreate this. I'm seeing the types inferred.
npm-test % tsc -v
Version 5.4.5
npm-test % node -v
v20.14.0
// package.json
{
"type": "module",
"dependencies": {
"@alpacahq/typescript-sdk": "0.0.29-preview",
"ts-node": "^10.9.2"
},
"devDependencies": {
"typescript": "^5.4.5"
}
}
// tsconfig.json
{
"compilerOptions": {
"module": "NodeNext",
"target": "ES6",
"moduleResolution": "NodeNext"
}
}
// test.ts
import { createClient } from "@alpacahq/typescript-sdk";
const client = createClient({
key: "my-paper-key",
secret: "my-paper-secret",
});
client.getAccount().then(console.log);
client.getAsset({ symbol_or_asset_id: "AAPL" }).then(console.log);
What node version are you on? What ts-node version are you on?
I was using nodemon
latest version, but now Im using "ts-node": "^10.9.2",
and still getting same error.
I am node version v20.8.0
typescript version 5.4.5
I restarted my computer and started with fresh new project, minimal package.json
and still getting it.
weird error when i attempt to run npx tsx test.ts
node:internal/errors:497
ErrorCaptureStackTrace(err);
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/zact/Projects/politician-trader/test/node_modules/@alpacahq/typescript-sdk/package.json
at __node_internal_captureLargerStackTrace (node:internal/errors:497:5)
at new NodeError (node:internal/errors:406:5)
at exportsNotFound (node:internal/modules/esm/resolve:268:10)
at packageExportsResolve (node:internal/modules/esm/resolve:542:13)
at resolveExports (node:internal/modules/cjs/loader:547:36)
at Module._findPath (node:internal/modules/cjs/loader:621:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1034:27)
at resolve (/Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:1:3084)
at resolveRequest (/Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:1:2618)
at /Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:1:3400
at m._resolveFilename (file:///Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-CFO5XQXL.mjs:1:832)
at Module._load (node:internal/modules/cjs/loader:901:27)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at <anonymous> (/Users/zact/Projects/politician-trader/test/test.ts:2:30)
at Object.<anonymous> (/Users/zact/Projects/politician-trader/test/test.ts:10:65)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Object.transformer (/Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:2:823)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at cjsLoader (node:internal/modules/esm/translators:284:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:234:7)
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
Try latest npm i @alpacahq/typescript-sdk@0.0.30-preview
out.
Try latest
npm i @alpacahq/typescript-sdk@0.0.30-preview
out.
ok I tested, still same error 🫤
I was able to get it working with your exact configuration. Try latest again 😄.
npm i @alpacahq/typescript-sdk@0.0.31-preview
I was able to get it working with your exact configuration. Try latest again 😄.
npm i @alpacahq/typescript-sdk@0.0.31-preview
I'm trying a ton of different things, but still same error. I am not sure what is happening brother, but still not working.
> npx --version
10.1.0
> npx tsx --version
tsx v4.15.6
node v20.8.0
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc test.ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"@alpacahq/typescript-sdk": "^0.0.31-preview",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
{
"compilerOptions": {
"module": "ESNext",
"resolveJsonModule": true,
"esModuleInterop": true,
"target": "esnext",
"noImplicitAny": true,
"noEmit": true,
"moduleResolution": "NodeNext",
"sourceMap": true,
"baseUrl": ".",
"forceConsistentCasingInFileNames": true,
"types": [
"node"
]
},
"exclude": [
"./node_modules"
]
}
$ npx tsx test.ts | pbcopy
node:internal/errors:497
ErrorCaptureStackTrace(err);
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/zact/Projects/politician-trader/test/node_modules/@alpacahq/typescript-sdk/package.json
at __node_internal_captureLargerStackTrace (node:internal/errors:497:5)
at new NodeError (node:internal/errors:406:5)
at exportsNotFound (node:internal/modules/esm/resolve:268:10)
at packageExportsResolve (node:internal/modules/esm/resolve:542:13)
at resolveExports (node:internal/modules/cjs/loader:547:36)
at Module._findPath (node:internal/modules/cjs/loader:621:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1034:27)
at resolve (/Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:1:3084)
at resolveRequest (/Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:1:2618)
at /Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:1:3400
at m._resolveFilename (file:///Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-CFO5XQXL.mjs:1:832)
at Module._load (node:internal/modules/cjs/loader:901:27)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at <anonymous> (/Users/zact/Projects/politician-trader/test/test.ts:1:30)
at Object.<anonymous> (/Users/zact/Projects/politician-trader/test/test.ts:9:65)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Object.transformer (/Users/zact/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-DfubRCxM.cjs:2:823)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at cjsLoader (node:internal/modules/esm/translators:284:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:234:7)
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v20.8.0
@zacharytyhacz have you figured it out already ?
I came to the same issue and managed to figure out that my tsconfig.json was misconfigured by manually transpiling using the "tsc" command and inspecting the generated JS which contained a require statement instead of the import statement so it was evident that the tsconfig was somehow off. Once that was resolved, npx tsc would run perfectly fine. Still having some struggles with ts-node-dev/ts-node though.
I did not, I just switched to @alpacahq/alpaca-trade-api
🫤
For the Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in ...
problem, make sure that your package.json contains the "type": "module"
line.
For the Cannot find module '@alpacahq/typescript-sdk' or its corresponding type declarations.
problem, make sure your tsconfig.json contains the "esModuleInterop": true
line inside the compilerOptions
.
And from my testing nodemon
and ts-node
did not really work, try tsx
(link) instead.
I have no idea why is happening
All I did was run
npm install @alpacahq/typescript-sdk
and it successfully installed and my project has no vulnerabilities.I tried all sorts of different tests and typescript just is not finding this package.
tsconfig.json
package.json
package-lock.json
When I play around with my
tsconfig.json
, sometimes this shows:this makes the error in my nvim go away
But when I run with
nodemon
I get this error