You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like quibble loader fails at managing such import. In my .test.js file i tried to replace alias path with await td.replaceEsm('#src/dependencies'); this lead to the following error :
TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#src/dependencies" is not defined in package /.../node_modules/quibble/package.json imported from /.../node_modules/quibble/lib/esm-import-functions.js
Full call stack :
at new NodeError (node:internal/errors:371:5)
at throwImportNotDefined (node:internal/modules/esm/resolve:442:9)
at packageImportsResolve (node:internal/modules/esm/resolve:819:3)
at moduleResolve (node:internal/modules/esm/resolve:973:21)
at defaultResolve (node:internal/modules/esm/resolve:1080:11)
at resolve (file:///.../node_modules/quibble/lib/quibble.mjs:12:25)
at resolve (file:///.../node_modules/quibble/lib/quibble.mjs:20:41)
at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
at ESMLoader.import (node:internal/modules/esm/loader:332:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1042:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
at importModuleDynamically (node:vm:381:46)
at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
at Object.dummyImportModuleToGetAtPath (node_modules/quibble/lib/esm-import-functions.js:8:70)
at Function.esmImportWithPath (node_modules/quibble/lib/quibble.js:117:35)
at Object.replaceEsModule (node_modules/testdouble/lib/replace/module/index.js:39:50)
at Module.replaceEsm (node_modules/testdouble/lib/replace/index.js:23:21)
at Context.<anonymous> (file:///.../lib/cron/crons/common/utils/parseSalary.test.js:18:14)
at processImmediate (node:internal/timers:466:21)
I don't know the exact way quibble is working internally. But it looks like the problem come from "dummyImportModuleToGetAtPath" function. When it try to "import", the original parentUrl context is lost, then package.json alias are lost too.
This is fixed in quibble 0.12.0 (via #123), and testdouble.js 3.23.0 picks it up.
Since 0.12.0, quibble resolves non-relative specifiers (package names and package.jsonimports like #src/*) from the file that called quibble.esm() / esmImportWithPath(). It skips files passed to ignoreCallsFromThisFile(), so td.replaceEsm('#src/dependencies') resolves from your test file. No --experimental-import-meta-resolve flag is needed.
I've added regression tests in #127 that cover quibble.esm, a self-ignoring wrapper (like td.replaceEsm) and esmImportWithPath with a #src/* mapping. To get the fix, upgrade to testdouble.js 3.23.0 or later (or quibble 0.12.0 or later if you use it directly). Closing, but please reopen if you still hit ERR_PACKAGE_IMPORT_NOT_DEFINED after upgrading.
Activity
Poyoman39 commentedon May 12, 2022
I don't know the exact way quibble is working internally. But it looks like the problem come from "dummyImportModuleToGetAtPath" function. When it try to "import", the original parentUrl context is lost, then package.json alias are lost too.
searls commentedon May 12, 2022
Paging @giltayar for help! 🙏
giltayar commentedon May 21, 2022
@Poyoman39 I'll look into it.
Add regression tests for mocking by package.json imports specifiers
rosston commentedon Oct 10, 2026
This is fixed in quibble 0.12.0 (via #123), and testdouble.js 3.23.0 picks it up.
Since 0.12.0, quibble resolves non-relative specifiers (package names and
package.jsonimportslike#src/*) from the file that calledquibble.esm()/esmImportWithPath(). It skips files passed toignoreCallsFromThisFile(), sotd.replaceEsm('#src/dependencies')resolves from your test file. No--experimental-import-meta-resolveflag is needed.I've added regression tests in #127 that cover
quibble.esm, a self-ignoring wrapper (liketd.replaceEsm) andesmImportWithPathwith a#src/*mapping. To get the fix, upgrade to testdouble.js 3.23.0 or later (or quibble 0.12.0 or later if you use it directly). Closing, but please reopen if you still hitERR_PACKAGE_IMPORT_NOT_DEFINEDafter upgrading.