jsenv / importmap-node-module

Generate importmap for node_modules
35 stars 4 forks source link

Exception: `baseUrl must be a string` #32

Closed canonic-epicure closed 3 years ago

canonic-epicure commented 3 years ago

This modules does not work out of the box for me:

nickolay@frontier:~/workspace/Bryntum/siesta-monorepo/siesta/examples/browser$ node generate-import-map.js
(node:12997) UnhandledPromiseRejectionWarning: TypeError: baseUrl must be a string.
--- base url ---
file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/
--- specifier ---
./
    at resolveUrl (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/import-map/src/resolveUrl.js:12:13)
    at tryUrlResolution (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/import-map/src/internal/tryUrlResolution.js:5:18)
    at file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/import-map/src/normalizeImportMap.js:51:24
    at Array.forEach (<anonymous>)
    at normalizeMappings (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/import-map/src/normalizeImportMap.js:36:25)
    at normalizeImportMap (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/import-map/src/normalizeImportMap.js:16:24)
    at getImportMapFromJsFiles (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/node-module-import-map/src/internal/from-js/getImportMapFromJsFiles.js:57:31)
    at getImportMapFromProjectFiles (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/node-module-import-map/src/getImportMapFromProjectFiles.js:59:36)
    at async Promise.all (index 0)
    at async writeImportMapFile (file:///home/nickolay/workspace/Bryntum/siesta-monorepo/siesta/examples/browser/node_modules/@jsenv/node-module-import-map/src/writeImportMapFile.js:31:22)

Steps to reproduce: 1) Clone the https://github.com/bryntum/siesta, revision: 730449a 2) npm i, npx tsc in it 3) cd examples/browser, npm i 4) node generate-import-map.js

Might be because of symlink in the node_modules (local installation)

Am I missing something?

canonic-epicure commented 3 years ago

Quick debugging showed that baseUrl in the code is URL instance, whereas expected is string. Should be something simple

canonic-epicure commented 3 years ago

Also, I'm using Node 12 if that matters (had to change the top-level await to .then())

dmail commented 3 years ago

I am checking

dmail commented 3 years ago

Thanks for the clear steps to reproduce, there is indeed an error thrown when projectDirectoryUrl is an url. I have fixed that in #33.

When generating importmap for your project I get the following logs.

image

For the first warning it seems I have to install a peer dependency.

If you want to get rid of the second warning you can add "main": "" in examples/browser/package.json. It indicates explicitely there is not entry file for this package and this repository won't try to find one.

canonic-epicure commented 3 years ago

Thanks for the quick resolution! I'll give it a try again.