Skip to content

Commit 7154a3f

Browse files
committed
fix: Allow determining TSR version in node 20
Without breaking node 16 This prevents the error: TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///Users/rjmunro/superflytv/sofie-timeline-state-resolver/packages/timeline-state-resolver-types/package.json" needs an import attribute of "type: json" at validateAttributes (node:internal/modules/esm/assert:88:15) at defaultLoadSync (node:internal/modules/esm/load:179:3) at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:379:24) at new ModuleJobSync (node:internal/modules/esm/module_job:341:34) at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:326:11) at loadESMFromCJS (node:internal/modules/cjs/loader:1411:24) at Module._compile (node:internal/modules/cjs/loader:1544:5) at Object..js (node:internal/modules/cjs/loader:1699:10) at Module.load (node:internal/modules/cjs/loader:1313:32) at Function._load (node:internal/modules/cjs/loader:1123:12) { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' Which I got when trying to build blueprints using node 20 when I was yarn link`ed to sofie-core, rather than using a pre-built version.
1 parent 0ab9870 commit 7154a3f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/shared-lib/src/tsr.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as TSR from 'timeline-state-resolver-types'
22
export { TSR }
33

4-
import * as tsrPkgInfo from 'timeline-state-resolver-types/package.json'
5-
export const TSR_VERSION: string = tsrPkgInfo.version
4+
// Dynamically import package.json to avoid import attributes error
5+
const TSR_VERSION = require('timeline-state-resolver-types/package.json').version
6+
7+
// Below line should work in Node.js 18+ and with bundlers that support import attributes, and replace the above
8+
// import { version as TSR_VERSION } from 'timeline-state-resolver-types/package.json' with { type: 'json' }
9+
10+
export { TSR_VERSION }

0 commit comments

Comments
 (0)