Welcome to the Linux Foundation Forum!

Lab 7.1 ERR_UNSUPPORTED_ESM_URL_SCHEME

When execting npm test in Lab 7.1 on WIndows 11 with Node v16.14.0 installed I get the following error:

  1. Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'f:'
  2. at new NodeError (node:internal/errors:371:5)
  3. at throwIfUnsupportedURLProtocol (node:internal/modules/esm/resolve:1033:11)
  4. at defaultResolve (node:internal/modules/esm/resolve:1103:3)
  5. at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
  6. at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
  7. at ESMLoader.import (node:internal/modules/esm/loader:332:22)
  8. at importModuleDynamically (node:internal/modules/esm/translators:106:35)
  9. at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
  10. at file:///F:/_jsnad/labs/ch-7/labs-1/test.mjs:4:39

Comments

  • Posts: 4

    I fixed the test by slightly changing the module loading according to your own tutorials in the chapter ;)
    Adding pathToFileURL

    1. import { pathToFileURL } from 'url'
    2. import { createRequire } from 'module'
    3. import assert from 'assert'
    4. const { resolve } = createRequire(import.meta.url)
    5. const { default: add } = await import(pathToFileURL(resolve('.')).toString())
    6.  
    7. assert(typeof add === 'function', 'function exported')
    8.  
    9. assert(add(15, 7) + add(11, 9) === 42, 'correct function exported')
    10.  
    11. console.log('passed!')
  • Posts: 160

    thanks @cscharr nicely done! code is being updated

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training