xpack / xpm-js

The xPack Project Manager command line tool
https://xpack.github.io/xpm/
MIT License
31 stars 7 forks source link

Windows: xpm 0.15.0 fails but 0.14.9 succeeds when instantiating project templates #164

Closed TommyMurphyTM1234 closed 1 year ago

TommyMurphyTM1234 commented 1 year ago

On Windows (10) this fails when using the latest xpm (0.15.0):

C:\temp>xpm --version
0.15.0

C:\temp>xpm init --template @micro-os-plus/hello-world-qemu-template@latest

Checking package @micro-os-plus/hello-world-qemu-template@latest metadata...
Processing @micro-os-plus/hello-world-qemu-template@1.4.1...
error: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at new NodeError (node:internal/errors:399:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
    at defaultResolve (node:internal/modules/esm/resolve:1135:3)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:525:22)
    at importModuleDynamically (node:internal/modules/esm/translators:110:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
    at Init.doInitWithTemplate (file:///C:/Users/Tommy%20Murphy/AppData/Roaming/npm/node_modules/xpm/lib/xpm/init.js:288:33)

But using the previous xpm version (0.14.9) succeeds:

C:\temp>xpm --version
0.14.9

C:\temp>xpm init --template @micro-os-plus/hello-world-qemu-template@latest

Checking package @micro-os-plus/hello-world-qemu-template@latest metadata...
Processing @micro-os-plus/hello-world-qemu-template@1.4.1...

Target? (cortex-m7f, cortex-m0, cortex-a15, cortex-a72, riscv-rv32imac, riscv-rv64imafdc, ?) [cortex-m7f]:
Programming language? (c, cpp, ?) [cpp]:
Build System? (cmake, meson, ?) [cmake]:
Creating the C++ project 'temp'...
Folder 'cmake' copied.
File 'CMakeLists.txt' generated.
File 'src/main.cpp' generated.
Folder 'include' copied.
Folder 'platform-qemu-cortex-m7f' copied.
File '.vscode/tasks.json' copied.
File '.vscode/settings.json' copied.
File '.clang-format' copied.
File 'README.md' generated.
File 'LICENSE' generated.
File 'package.json' generated.

On Linux both work fine.

ilg-ul commented 1 year ago

The problem is related how paths should be passed to dynamic imports. For ESM modules, the path must be a full URLs, especially on Windows.

Fixed on 2023-05-18.

TommyMurphyTM1234 commented 1 year ago

Just to confirm that 0.15.1 addresses the issue for me - thanks.