d3p1 / semantic-releasify

A GitHub Action to fully automate version management and package publishing
MIT License
0 stars 0 forks source link

Unable to use ECMAScript modules #2

Open d3p1 opened 1 year ago

d3p1 commented 1 year ago

Preconditions & Environment

Steps to reproduce

  1. Execute npm run all

Expected result

The source code is compiled correctly and the build is generated on dist/ folder

Actual result

When it is executed npm run all there is an error related to jest and ncc.

The jest error is the following:

Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

 Details:

    /workspaces/semantic-release-action/node_modules/semantic-release/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { createRequire } from "node:module";
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

       5 |  * @link        https://semantic-release.gitbook.io/semantic-release/developer-guide/js-api
       6 |  */
    >  7 | import semanticRelease from 'semantic-release';
         | ^
       8 | import * as core from '@actions/core';

The error related to ncc is:

TypeError: Cannot read properties of undefined (reading 'path')
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:253938
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:13:45737
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:253466
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:1866171
    at finishWithoutResolve (/workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:484092)
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:484908
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:485543
    at eval (eval at create (/workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:20:75523), <anonymous>:27:1)
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:632875
    at /workspaces/semantic-release-action/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:631938
d3p1 commented 1 year ago

The ECMAScript syntax is causing issues, but it is necessary to use it because semantic-release is an ECMAScript module.

For the moment, just to release the action and use it in needed projects, the following hot fixes are going to be done:

Then, these issues will be solved with the correct approach.