Questions/Comments regarding medplum/core
# support
m
I am getting some build errors I do not understand. I am trying to build a small program that uses @medplum/core. The errors I am getting are these: node_modules/@medplum/core/dist/esm/index.d.ts:14:40 - error TS2307: Cannot find module 'pdfmake/interfaces' or its corresponding type declarations. 14 import type { CustomTableLayout } from 'pdfmake/interfaces'; node_modules/@medplum/core/dist/esm/index.d.ts:51:43 - error TS2307: Cannot find module 'pdfmake/interfaces' or its corresponding type declarations. 51 import type { TDocumentDefinitions } from 'pdfmake/interfaces'; node_modules/@medplum/core/dist/esm/index.d.ts:52:38 - error TS2307: Cannot find module 'pdfmake/interfaces' or its corresponding type declarations. 52 import type { TFontDictionary } from 'pdfmake/interfaces'; Found 3 errors in the same file, starting at: node_modules/@medplum/core/dist/esm/index.d.ts:14 The weird thing is that I am explicitly including both "@types/pdfmake": "^0.2.9" and "pdfmake": "^0.2.9" in the package.json. Also - I note that I get other errors from @medplum/core if I don't include "DOM" in the lib: declaration. Does @medplum/core assume that it is running in a browser? I would have thought that the core package would not depend on browser-only constructs.
r
@mitch_83302 - any chance the CLI will work for you for this small application? https://www.medplum.com/docs/cli @medplum/core does run server side on on our servers. Dependencies do need to be set up
m
I am able to get it to work, it's just that the compilation errors show up. The code that it is referring to isn't going to be executed so there is no problem. But of course I want to understand why the errors are there so I can avoid them.
r
ahh got it. Some unused dependencies are the issue
m
The dependency appears to be pdfmake, which I have explicitly included in the package.json
Yes.
r
m
Interesting... I will look at that. But why does the code refer to pdfmake at all? It seems to me that that would be part of a front-end package, not core. Also, I get even more errors if I don't include DOM in the library configuration of tsconfig - which means that at least some of the code believes it is running in a browser.
r
@mitch_83302 while pdfmake is not a runtime dependency of medplum core, we do use the the types they export for the createPdf method
One thing to note id that our example applications don’t explicitly import pdf make
This kight be due to a difference in eslint configuration aettings. Would you mind sharinf your package.json file to help us debug
m
Here it is... As you can see, pdfmake itself and the types are both explicitly included, so I don't understand the message I posted above:
$ more package.json { "name": "medplum-initial-test", "version": "3.2.6", "private": true, "type": "module", "scripts": { "build": "npm run clean && npm run lint && tsc", "clean": "rimraf dist", "lint": "eslint src/", "prettier": "prettier --write ." }, "prettier": { "printWidth": 120, "singleQuote": true, "trailingComma": "es5" }, "eslintConfig": { "parserOptions": { "project": "./tsconfig.json" }, "extends": [ "@medplum/eslint-config" ], "root": true }, "devDependencies": { "@medplum/bot-layer": "^3.2.7", "@medplum/cli": "^3.2.7", "@medplum/core": "^3.2.7", "@medplum/eslint-config": "^3.2.7", "@medplum/fhirtypes": "^3.2.7", "@medplum/mock": "^3.2.7", "@playwright/test": "^1.46.1", "@types/node": "^22.2.0", "@types/node-fetch": "^2.6.11", "@types/pdfmake": "^0.2.9", "@types/ssh2-sftp-client": "^9.0.3", "fast-glob": "3.3.2", "form-data": "4.0.0", "node-fetch": "2.7.0", "pdfmake": "^0.2.9", "rimraf": "5.0.9", "ssh2-sftp-client": "11.0.0", "stripe": "16.7.0", "typescript": "5.5.4" }, "include": [ "src" ] }
@rahul1 One further thought... Note that I removed most but all of the stuff I don't need. I don't think I need the sftp client and the fast-glob. I can try taking those out but I don't think they're the problem.
r
Hi @mitch_83302 thanks for your patience! I tried setting up a minimal project to reproduce on my side, and wasn't yet able to reproduce. Here are the steps I took 1. Clone the
medplum-demo-bots
repo (https://github.com/medplum/medplum-demo-bots) 2. Replace package.json with the contents copied below (essentially the same as yours, plus
vitest
) 3.
npm i
4.
npm run build
Copy code
{
  "name": "medplum-initial-test",
  "version": "3.2.6",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "npm run clean && npm run lint && tsc",
    "clean": "rimraf dist",
    "lint": "eslint src/",
    "prettier": "prettier --write ."
  },
  "prettier": {
    "printWidth": 120,
    "singleQuote": true,
    "trailingComma": "es5"
  },
  "eslintConfig": {
    "parserOptions": {
      "project": "./tsconfig.json"
    },
    "extends": [
      "@medplum/eslint-config"
    ],
    "root": true
  },
  "devDependencies": {
    "@medplum/bot-layer": "^3.2.7",
    "@medplum/cli": "^3.2.7",
    "@medplum/core": "^3.2.7",
    "@medplum/eslint-config": "^3.2.7",
    "@medplum/fhirtypes": "^3.2.7",
    "@medplum/mock": "^3.2.7",
    "@playwright/test": "^1.46.1",
    "@types/node": "^22.2.0",
    "@types/node-fetch": "^2.6.11",
    "@types/pdfmake": "^0.2.9",
    "@types/ssh2-sftp-client": "^9.0.3",
    "fast-glob": "3.3.2",
    "form-data": "4.0.0",
    "node-fetch": "2.7.0",
    "pdfmake": "^0.2.9",
    "rimraf": "5.0.9",
    "ssh2-sftp-client": "11.0.0",
    "stripe": "16.7.0",
    "typescript": "5.5.4",
    "vitest": "2.0.5"
  },
  "include": [
    "src"
  ]
}
In addition, after running
npm i
, I was able to confirm tha the pdfmake types files were installed to
node_modules/@types/pdfmake/interfaces.d.ts
In you project, could you confirm that this file is installed?
You might also want to compare your
tsconfig.json
file to the one in the repo I provided. We don't require
DOM
in that repo, we just use
esnext
m
I do see the pdfmake file you indicate. It's very odd.
Are you compiling the src files of the demo bots or my single source file. The reason I ask is that the demo bots is compiled by a more complex process involving esbuild-script.mjs
r
Yes, I removed that from my package.json before I built, so no es-build involved. THe package.json I copied above is what I used install + build
I have a sneaking suspicion this is a tsconfig issue somewhere
If you follow my steps of modifying the demo-bots repo, what is your experience?
m
The problem is that demo-bots is totally different in structure. When I remove all the code from the src directory, I don't get any errors, but I don't see anything building at all. I will look at it again today.
When I say it's different in structure, I mean that it is compiled by a separate file esbuild-script.mjs. I need to look at that carefully to see why it's missing the app.ts file that I put in the src directory.
I am still not sure what was wrong about the other package, but I now have it working without error.
r
> When I say it's different in structure, I mean that it is compiled by a separate file esbuild-script.mjs. That's right, the vanilla package.json from
demo-bots
uses esbuild. I had modified it before running to only use tsc, to try to reproduce your envronment
Not 100% sure why your package.json wasn't working, as I tred to copy that verbatim in my test
But I'm glad to hear it was solved!!
Are you using npm or yarn?
m
I use npm. I have never understood what the shortcomings of npm are supposed to be, or what the advantages of yarn are. To get it to work I had to fight quite a bit with the differences between commonjs and modules, but I got it working correctly now.
The error that I was getting was particularly odd because I could definitely see that the package it was complaining about was installed, just in the spot it should be (and that you indicated). My view is that putting the pdf stuff (and the bits that depend on the DOM libraries) into core isn't ideal, but I will just copy what I have working to any new projects.
A question that I still have is what the advantages of vite are. I haven't tried yet to remove it fully from the package, but I can imagine using other testing frameworks such as jest or playwright, so I might look into that at some point.
r
> have never understood what the shortcomings of npm We're with you on this. I only ask because we've seen yarn caching do some odd things in the past, which has led to weird beuild errors
> My view is that putting the pdf stuff (and the bits that depend on the DOM libraries) Our goal is that Medplum core does not take a dependency on DOM. One of the reasons I chose to test against
medplum-demo-bots
is that this is pure server-side code, and the TSconfig in that repo doesn't include the DOM at all
m
I think that when we set lib to "NodeNext" it is getting the DOM stuff as well. I am not expert on this stuff (nodejs/js development is a bit convoluted, unfortunately - I say this even though I like working in it) but I worry about running in production against anything NodeNext because stuff can get removed from it later.
172 Views