Skip to content

Error when trying to compile my typescript project including the ojp-sdk library #113

@iKK001

Description

@iKK001

Inside the packge.json I add the library to the dependencies:

"dependencies": {
    "ojp-sdk": "0.12.5"
}

Inside my code, I import the library (and needed jsdom) as follows:

import * as OJP from 'ojp-sdk';
import jsdom from 'jsdom';

const { JSDOM } = jsdom;
global.DOMParser = new JSDOM().window.DOMParser;

However when compiling, I get the following error message:

yarn run v1.22.19
warning ../../../../../package.json: No license field
$ nest start
/Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/stops/stops.service.js:47
const OJP = __importStar(require("ojp-sdk"));
                         ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/node_modules/ojp-sdk/lib/index.js from /Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/stops/stops.service.js not supported.
Instead change the require of index.js in /Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/stops/stops.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/stops/stops.service.js:47:26)
    at Object.<anonymous> (/Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/teddies/teddies.controller.js:42:25)
    at Object.<anonymous> (/Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/teddies/teddies.module.js:11:30)
    at Object.<anonymous> (/Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/app.module.js:19:26)
    at Object.<anonymous> (/Users/stephankorner/Documents/Dokumente_KOS/Programieren/NodeJS_private/teddy-api/dist/main.js:40:22) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.18.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

My tsconfig.json File looks as follows.

Please note that I cannot change CommonJS or ES6 due to other libraries in my project !

{
  "compilerOptions": {
    "module": "CommonJS",
    "target": "ES6",
    "moduleResolution": "Node",
    "esModuleInterop": true,
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false    
  }
}

Is there any way to update the ojp-sdk library so that it can work with the config inside my package.json ?

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