IBM / cloudant-node-sdk

Cloudant SDK for Node.js
Apache License 2.0
28 stars 13 forks source link

Dependency issue #1536

Closed robhowe-A closed 3 months ago

robhowe-A commented 4 months ago

Describe the bug I'm using the SDK Typescript test to create a database and populate. I have Gulp + Typescript developer space. I get stopped at a compile error referring axios.js. I've tried multiple fixes from website searches and playing with the source/package files of axios. I did not try downgrading axios, which was one of the search solutions, as it would not be the newest version.

To Reproduce Install cloudant in Gulp + Typescript environment

npm install @ibm-cloud/cloudant

Expected behavior It is expected the dependency agrees to module use cases.

Screenshots

2024-05-29 18_48_14-html ts - webapp  Codespaces_ vigilant trout  - Visual Studio Code

Output

[23:41:13] [SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'] {
  line: 1,
  column: 1,
  annotated: '\n' +
    '/workspaces/<appName>/node_modules/ibm-cloud-sdk-core/node_modules/axios/index.js:1\n' +
    "import axios from './lib/axios.js';\n" +
    '^\n' +
    "ParseError: 'import' and 'export' may appear only with 'sourceType: module'",
  stream: Labeled {
    _readableState: ReadableState {
      objectMode: true,
      highWaterMark: 16,
      buffer: BufferList { length: 0 },
      length: 0,
      pipes: [Labeled],
      pipesCount: 1,
      flowing: true,
      ended: false,
      endEmitted: false,
      reading: true,
      sync: false,
      needReadable: true,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      destroyed: false,
      defaultEncoding: 'utf8',
      awaitDrain: 0,
      readingMore: false,
      decoder: null,
      encoding: null
    },
    readable: true,
    _events: [Object: null prototype] {
      end: [Array],
      finish: [Function],
      error: [Function (anonymous)],
      unpipe: undefined,
      drain: undefined,
      close: undefined,
      data: [Function: ondata],
      _mutate: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: true,
      highWaterMark: 16,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 1,
      writing: true,
      corked: 0,
      sync: true,
      bufferProcessing: false,
      onwrite: [Function (anonymous)],
      writecb: [Function: nop],
      writelen: 1,
      bufferedRequest: null,
      lastBufferedRequest: null,
      pendingcb: 1,
      prefinished: false,
      errorEmitted: false,
      bufferedRequestCount: 0,
      corkedRequestsFree: [CorkedRequest]
    },
    writable: true,
    allowHalfOpen: true,
    _options: { objectMode: true },
    _wrapOptions: { objectMode: true },
    _streams: [ [DestroyableTransform] ],
    length: 1,
    label: 'syntax',
    [Symbol(shapeMode)]: true,
    [Symbol(kCapture)]: false
  }
}

Must gather (please complete the following information): Node v20.13.1 ibm-cloud-sdk-core@4.3.0 axios@1.7.2

Additional context No solution found of Javascript or Typescript.

ricellis commented 4 months ago

The error looks a lot like something is trying to use ESM style code in CommonJS environment.

I'm not familar with gulp, but the pubished @ibm-cloud/cloudant has been used with both CommonJS and ESM module styles and with both TS and JS in Node without this error so I don't think this is a problem with the library/dependencies.

I'm using the SDK Typescript test to create a database and populate

I'm not sure exactly which code "SDK Typescript test" is referring to here, but if you are copy/pasting any of our TS examples then you likely need a gulpfile.ts with ts-node rather than a gulpfile.js. If you don't want/need TS you can just use JS - we have some examples in the README in both formats (the JS twisties are collapsed by default).

Install cloudant in Gulp + Typescript environment

What module system are you trying to use though? Do you have a module entry in your package.json? If you are using typescript and transpiling then what tsconfig settings are you using? Did you try gulpfile.mjs or gulpfile.cjs to force use of a specific module system (or the equivalent ~mts~ [edit looks like mts is unsupported] and cts for TS). It looks like gulp support for TS and ESM might be a little awkward.

ricellis commented 3 months ago

I'm closing this as stale. Please comment with additional information if you want to re-open (or feel free to share if you found a solution to the problem). Thanks.