Skip to content

Unable to initialize library #307

Open

Description

@deadnight7

The library is not getting instantiated, Created a basic node project and trying to instantiate the library. Does not work.

index.js

const HTTPSnippet = require('httpsnippet').HTTPSnippet

const snippet = new HTTPSnippet({
    method: 'GET',
    url: 'http://mockbin.com/request',
});

const options = { indent: '\t' };
const output = snippet.convert('shell', 'curl', options);
console.log(output);

Package JSON

{
  "name": "http-code-generator",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "httpsnippet": "^2.0.0"
  }
}

Getting this below error

const snippet = new HTTPSnippet({
                ^

TypeError: HTTPSnippet is not a constructor
    at Object.<anonymous> (/Users/cpandit/WebstormProjects/untitled1/index.js:6:17)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
➜  untitled1 

Activity

  1. deadnight7 commented on Nov 4, 2022

    @deadnight7
    Author

    Update the README docs needs to be updated
    I tried doing a named export, which should have been default export in httpsnippet library, like this

    const HTTPSnippet = require('httpsnippet')
  2. cocowalla commented on Oct 14, 2024

    @cocowalla

    Did you ever get this working? It worked for me prior to v3, but now I get the same:

    const HTTPSnippet = require('httpsnippet');
    
    const snippet = new HTTPSnippet({
      method: 'GET',
      url: 'http://mockbin.com/request',
    });

    Results in:

    TypeError: HTTPSnippet is not a constructor
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions