hapijs / lab

Node test utility
Other
739 stars 176 forks source link

Babel Preset transform is breaking on updating node version #1066

Open sathyalog opened 1 year ago

sathyalog commented 1 year ago

Support plan

Context

How can we help?

Hi Team,

In our application earlier we were using node 16.20.0 with webpack 4 and hapi libraries used for multiple purpose and hapi lab(24.0.0) used for unit test cases. We have a babel config file(transform.js) like shown in the code snippet used in our package json script

let transformed = Babel.transform(content, {
        presets: [
            "@babel/preset-react",
            "@babel/typescript",
            [
                "@babel/preset-env",
                {
                    targets: {
                        node: 12,
                    },,
                },
            ],
        ],
        filename: filename,
        sourceMap: "inline",
        sourceFileName: filename,
        auxiliaryCommentBefore: "$lab:coverage:off$",
        auxiliaryCommentAfter: "$lab:coverage:on$",
        plugins: [
            "@babel/plugin-proposal-export-default-from",
            "@babel/plugin-proposal-class-properties",
            "@babel/plugin-proposal-private-property-in-object",
            "@babel/plugin-proposal-private-methods",
            "@babel/plugin-transform-runtime",
            "@babel/plugin-syntax-dynamic-import",
            [
                "module-resolver",
                {
                    alias: {
                        "@govuk-jsx": path.join(
                            path.dirname(
                                require.resolve(
                                    "@xgovformbuilder/govuk-react-jsx"
                                )
                            ),
                            "/components"
                        ),
                    },
                },
            ],
            [
                "babel-plugin-transform-import-ignore",
                {
                    patterns: [".css", ".scss", "wildcard/*/match.css"],
                },
            ],
        ],
        exclude: ["node_modules/**"],
        ignore: ["../node_modules", "node_modules"],
    });

package.json script: "test-lab-cov": "lab -T test/.transform.js test/.setup.js ./*/.test.* -S -v -t 87 -r console -o stdout -r lcov -o test-coverage/lab/lcov.info -r html -o test-coverage/lab/unit-test.html -r junit -o test-results/lab/unit-test.xml -I version -l",

### PROBLEM: Now we have upgraded our application from node 16.20.0 to node 18.16.0 and upgraded webpack 4 to webpack 5. Now after this upgrade, when we run the script test-lab-cov. It throws the following errors like shown in screenshots. I tried upgrading minor versions of hapi lab libraries, babel core, babel eslint etc but still the error is not resolved.

Can anyone please let me know where its going wrong and how can we fix this to work hapi lab with node 18.16.0?

Pls advise if you have any suggestions.

Thanks

Screenshot 2023-09-14 at 09 12 18 Screenshot 2023-09-14 at 09 12 36