Skip to content

test/hook/v18-static-import-assert.mjs fails with SyntaxError: Unexpected identifier 'assert' with Node.js 22 #73

@richardlau

Description

@richardlau

Expected Behavior

Test suite passes with Node.js 22.

Actual Behavior

not ok 21 test/hook/v18-static-import-assert.mjs
   ---
   stdout: ''
   stderr: >-
     file:///home/iojs/tmp/citgm_tmp/57e69ae9-aca1-49ae-aae0-acf7ab1693e1/import-in-the-middle/test/fixtures/json.mjs:5
     import coolFile from './something.json' assert { type: 'json' }
                                             ^^^^^^
     SyntaxError: Unexpected identifier 'assert'
         at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
         at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
         at callTranslator (node:internal/modules/esm/loader:416:14)
         at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:422:30)
     Node.js v22.0.0
   ...

Steps to Reproduce the Problem

This is seen in CITGM runs for Node.js 22 (and main) where support for import assertions has been removed, replaced by import attributes.
e.g. https://ci.nodejs.org/job/citgm-smoker/3421/nodes=rhel8-x64/testReport/junit/(root)/citgm/import_in_the_middle_v1_7_3/

This appears to be coming from the fixture:
https://github.com/DataDog/import-in-the-middle/blob/00b01fff1f5b69dd25e307593ec54d1d8abb4844/test/fixtures/json.mjs#L5

At first glance it looks fairly simple to update the fixture (replace assert with with) but it seems like the GitHub Actions here test on a selection of older Node.js 18 and 20 releases which do not have support for import attributes.

FTR support for import attributes landed in Node.js 18 in 18.20.0 and Node.js 20 in 20.10.0. There are no plans to remove import assertions from Node.js 18 or 20.

Specifications

  • Version:
  • Platform:
  • Subsystem:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions