garronej / denoify

🦕For NPM module authors that would like to support Deno but do not want to write and maintain a port.
http://denoify.land
MIT License
917 stars 21 forks source link

Error: Can't locate lib/adapters/http from {"type":"DENO.LAND URL","isStd":false,"baseUrlWithoutBranch":"https://deno.land/x/axiod","branch":"0.26.2","pathToIndex":"mod.ts"} #93

Closed mashirozx closed 1 year ago

mashirozx commented 1 year ago
Can't lookup version 1.3.6 for module {"type":"DENO.LAND URL","isStd":false,"baseUrlWithoutBranch":"https://deno.land/x/axiod","branch":"0.26.2","pathToIndex":"mod.ts"}, falling back to 0.26.2
/Users/mashiro/Code/lib/megalodon/node_modules/denoify/bin/denoify.js:7
    throw error;
    ^

Error: Can't locate lib/adapters/http from {"type":"DENO.LAND URL","isStd":false,"baseUrlWithoutBranch":"https://deno.land/x/axiod","branch":"0.26.2","pathToIndex":"mod.ts"}
    at /Users/mashiro/Code/lib/megalodon/node_modules/denoify/lib/resolveNodeModuleToDenoModule/resolveNodeModuleToDenoModule.js:379:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async callee (/Users/mashiro/Code/lib/megalodon/node_modules/denoify/tools/addCache.js:19:33)
    at async denoifyImportExportStatement (/Users/mashiro/Code/lib/megalodon/node_modules/denoify/lib/denoifyImportExportStatement.js:77:26)
    at async /Users/mashiro/Code/lib/megalodon/node_modules/denoify/lib/denoifySingleFile.js:105:60
    at async Promise.all (index 0)
    at async replaceAsync (/Users/mashiro/Code/lib/megalodon/node_modules/denoify/tools/replaceAsync.js:12:18)
    at async denoifySingleFile (/Users/mashiro/Code/lib/megalodon/node_modules/denoify/lib/denoifySingleFile.js:104:38)
    at async transformSourceCodeString (/Users/mashiro/Code/lib/megalodon/node_modules/denoify/lib/denoify.js:96:39)
    at async transformCodebase (/Users/mashiro/Code/lib/megalodon/node_modules/denoify/tools/transformCodebase.js:13:49)

Node.js v18.16.0 Denoify 1.5.3

I just want to replace npm lib axios with deno lib axiod, my configuration:

// @ts-check

/** @type { import('denoify/lib/config/parseParams').DenoifyParams } */
const config = {
    ports: {
        axios: "https://deno.land/x/axiod/mod.ts"
    }
 }

module.exports = config;

related issue: #60

mashirozx commented 1 year ago

I'm not sure is my configuration is correct?

garronej commented 1 year ago

Thanks for reporting.
I thing this is a bug. It should work. I wont be able to patch before tonight. 😕

mashirozx commented 1 year ago

Never mind, thank you

garronej commented 1 year ago

Hi @mashirozx,
I'm sorry but I can't reproduce. I've updated the demo repo, it work as expected.

image

https://github.com/garronej/my_dummy_npm_and_deno_module/commit/1577e7f6ab83389536f208da0777e514174a9735

Maybe it was only a teporary issue?

mashirozx commented 1 year ago

@garronej Hi, thanks! I noticed something like this:

image

There is no export of AxiosResponse and AxiosRequestConfig in axiod. Will it be the reason of this error message?

garronej commented 1 year ago

Hi @mashirozx,

With this exact import statment and axiosd as polifill (just like you did) I'm not getting any error message compile time nor runtime...

maybe you can provide a reproduction path with a fork of the demo setup: https://github.com/garronej/my_dummy_npm_and_deno_module

mashirozx commented 1 year ago

@garronej Thanks for the reply, tried the same as the sample (I think), but really don't know why it trying to fetch axiod 1.3.6 on deno land, which is only the axios version:

image

This is my project, if it's convenient for you, please have a look 🙏: https://git.mashiro.top/test/megalodon/-/tree/master/megalodon

garronej commented 1 year ago

@mashirozx,

The problem is with src/axios.d.ts, Denoify don't know what to make of it.
You can either tell denoify to ignore this file:

src/axios.d.ts

// @denoify-ignore

declare module 'axios/lib/adapters/http'

https://docs.denoify.land/special-comments

Or provide a specific implémentation for deno

src/axios.d.deno.ts

declare module "foo" {
    export default function foo(): string;
}

Denoify will just cp src/axios.d.deno.ts deno_dist/axios.d.ts

Hope it helps.

mashirozx commented 1 year ago

You are right! thanks a lot! ❤️