JCMais / node-libcurl

libcurl bindings for Node.js
https://npmjs.org/package/node-libcurl
MIT License
660 stars 117 forks source link

No loader error in TypeScript #386

Closed EngineerHus closed 7 months ago

EngineerHus commented 1 year ago

Hello, I am running a rocketchat and jira server on my docker container. I am trying to make a curl request using the node-libcurl library. However I am facing an issue which I hope you can shed some light on. The error is: node_modules/node-libcurl/dist/Multi.js:5:25: error: No loader is configured for ".node" files: node_modules/node-libcurl/lib/binding/node_libcurl.node

The code is:

import nodeLoader from 'node-loader';
import fetch from 'node-fetch';
import {
    IHttp,
    IModify,
    IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import {
    ISlashCommand,
    SlashCommandContext,
} from '@rocket.chat/apps-engine/definition/slashcommands';
import axios from 'axios';

export class h implements ISlashCommand {
    public command = 'h';
    public i18nParamsExample = '';
    public i18nDescription = '';
    public providesPreview = false;

    public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
        const user = 'user';
        const pass = 'password';
        const data1 ={ "fields": { "project": { "key": "HUS" },"summary": "1", "description": "2","issuetype": { "name": "Bug" }}};

        const { curly } = require('node-libcurl');
        const { data } = await curly.post('http://localhohst:8080/rest/api/2/issue',{
          postFields: JSON.stringify(data1),
          httpHeader: [
            'Content-Type: application/json'],
        })

        console.log("\n\nThe data from CURL is %", data);
}};

node version is 14.21.3 npm: 9.6.4

My tsnconfig.json
"compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "strictNullChecks": true,
    "noImplicitReturns": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "paths": {
      "@": [
        "./"
   ],
      "*": [
        "src/*",
        "node_modules/*"
]},},
"include": [
    "**/*.ts"
    ],
}

Thanks in Advance

andrew1931 commented 7 months ago

I had the same issue with esbuild. --loader:.node=copy resolved the issue

JCMais commented 7 months ago

Sorry but I cannot offer support for custom loaders atm, this is going to be an issue with most native addons, doing something similar to what @andrew1931 suggest above is the only solution.