Miramac / node-qualtrics-api

MIT License
0 stars 0 forks source link

Cannot import Qualtrics from qualtrics-api #21

Closed Agugori closed 1 year ago

Agugori commented 1 year ago

Hello there, im trying to import Qualtrics but i got this error 'Qualtrics' can only be imported by using 'import Qualtrics = require("qualtrics-api")' or by turning on the 'esModuleInterop' flag and using a default import.ts(2617)

this is the way im importing it, im already try to do it without the breakets

Captura de pantalla 2023-01-29 a la(s) 11 16 40

this is my tsconfig.ts

Captura de pantalla 2023-01-29 a la(s) 11 17 46

Agugori commented 1 year ago

im using it on a nestjs app

Miramac commented 1 year ago

sorry for the late response... For now you have to use this: import Qualtrics = require('qualtrics-api');. I will probably change it in the future

This code worked for me without turning on the 'esModuleInterop' flag.

import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import Qualtrics = require('qualtrics-api');

const config = {
  apiToken: '<apiToken>',
  baseUrl: 'https://eu.qualtrics.com/API/v3/',
  defaultDirectory: '<defaultDirectory>',
};
const qualtrics = new Qualtrics(config);

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  async getHello(): Promise<string> {
    return qualtrics.whoami();
  }
}