Conversation
unitTests/apiTests/mqtt-test.mjs
Outdated
| import { setupTestApp } from './setupTestApp.mjs'; | ||
| import { get as env_get, setProperty } from '#js/utility/environment/environmentManager'; | ||
| import { createRequire } from 'node:module'; | ||
| const { get: env_get, setProperty } = createRequire(import.meta.url)('#js/utility/environment/environmentManager'); |
There was a problem hiding this comment.
What's going on here? Is this fixing a lint warning or an actual functionality bug?
I've seen a lot of warnings from trying to import CommonJS files. I usually can resolve them by doing:
import * as environmentManager from '#js/utility/environment/environmentManager';
const { get: env_get, setProperty } = environmentManager ;I don't love this pattern, but then again I don't love creating a require() instance either.
There was a problem hiding this comment.
That's addressing this error that was only seen in node 24
Exception during run: file:///home/runner/work/harper/harper/unitTests/apiTests/setupTestApp.mjs:3
import { setProperty } from '#js/utility/environment/environmentManager';
^^^^^^^^^^^
SyntaxError: The requested module '#js/utility/environment/environmentManager' does not provide an export named 'setProperty'
at #asyncInstantiate (node:internal/modules/esm/module_job:319:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:422:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:661:26)
at async formattedImport (/home/runner/work/harper/harper/node_modules/mocha/lib/nodejs/esm-utils.js:10:14)
at async exports.loadFilesAsync (/home/runner/work/harper/harper/node_modules/mocha/lib/nodejs/esm-utils.js:152:20)
at async singleRun (/home/runner/work/harper/harper/node_modules/mocha/lib/cli/run-helpers.js:168:3)
at async exports.handler (/home/runner/work/harper/harper/node_modules/mocha/lib/cli/run.js:379:5)
There was a problem hiding this comment.
All for any other better feeling solution that addresses the issue. This is just the first one that seemed to do the trick...
There was a problem hiding this comment.
Yeah, this is the same issue I was running into yesterday with Harper v5 and Node.js 22.17.0. I think the import * as whatever from 'thing', then destructuring into a variable is the cleanest solution.
There was a problem hiding this comment.
I'll give that a shot here before merging. don't want to get an ugly pattern started... brb
There was a problem hiding this comment.
updated and rebased, so now this pr is only this change
No description provided.