transpiling esm dependencies with ts-node #1308
Answered
by
talentlessguy
talentlessguy
asked this question in
Q&A
-
I'm writing tests for my balance-crypto library and I'm trying to make uvu, ts and ts-node work together. Is there a good way to transpile dependencies of a library during running ts-node? atm i get this error because of an ES dependency:
files my tsconfig: {
"include": ["src", "./example.ts"],
"compilerOptions": {
"module": "ESNext",
"target": "ES2019",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"noEmit": true,
"lib": ["ES2019"],
"preserveSymlinks": true
},
"ts-node": {
"transpileOnly": true,
"compilerOptions": {
"module": "commonjs"
},
"include": ["test/**/*"],
"exclude": ["node_modules"]
}
} test suite: import { suite } from 'uvu'
import assert from 'uvu/assert'
import { balance } from '../src/index'
const t = suite('blockcypher')
t('should reject invalid address', async () => {
try {
await balance('invalid', 'BTC')
} catch (e) {
assert.equal(e.message, 'Invalid address "invalid" for BTC')
assert.instance(e, Error)
}
})
t('should support BTC, LTC, DASH and DOGE addresses', async () => {
const balances = [
{
coin: 'BTC',
address: '3PxedDftWBXujWtr7TbWQSiYTsZJoMD8K5'
},
{
coin: 'LTC',
address: 'MBk5YpWiqWmWC1EVY28qfoKygGQwX343Uu'
},
{
coin: 'DASH',
address: 'XnTVbwYQdkQNa3ZRsyAA4y1fgMAtmEgb61'
},
{
coin: 'DOGE',
address: 'DBXu2kgc3xtvCUWFcxFE3r9hEYgmuaaCyD'
}
]
for (const b of balances) {
const result = await balance(b.address, b.coin)
assert.is.not(result?.balance, null)
assert.is(result?.asset, b.coin)
}
})
t.run() |
Beta Was this translation helpful? Give feedback.
Answered by
talentlessguy
May 9, 2021
Replies: 2 comments 2 replies
-
the best solution would be not transpiling anything at all and relying only on native esm if it possible that way anyone who knows please share how |
Beta Was this translation helpful? Give feedback.
2 replies
-
This is how I made it work:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
talentlessguy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is how I made it work: