Skip to content

Commit db4bb4c

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 db4bb4c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/shared-lib/src/tsr.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
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+
let TSR_VERSION: string = ''
6+
try {
7+
const tsrPkgInfo = require('timeline-state-resolver-types/package.json')
8+
TSR_VERSION = tsrPkgInfo.version
9+
} catch (_e) {
10+
TSR_VERSION = ''
11+
}
12+
13+
// Below line should work in Node.js 18+ and with bundlers that support import attributes, and replace the above
14+
// import { version as TSR_VERSION } from 'timeline-state-resolver-types/package.json' with { type: 'json' }
15+
16+
export { TSR_VERSION }

0 commit comments

Comments
 (0)