Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iKK001 opened this issue Oct 12, 2024 · 0 comments

Comments

@iKK001
Copy link

iKK001 commented Oct 12, 2024

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant