nartc / mapper

🔥 An Object-Object AutoMapper for TypeScript 🔥
https://automapperts.netlify.app/
MIT License
980 stars 87 forks source link

No "exports" main defined in node_modules/@automapper/classes/package.json #587

Closed gabrielkim13 closed 8 months ago

gabrielkim13 commented 8 months ago

Is there an existing issue for this?

Describe the issue

Hi there, @nartc!

First of all, thank you for taking the time to merge pending PRs and releasing version 8.8.0 of automapper-ts!

Unfortunately, it seems that some of these changes have introduced a minor issue in the @automapper/classes package:

image

Turns out that "./" is not a valid key for package.json's exports option.

For me, this is an issue when using pkg to generate single-executable Node binaries, as I get the following error:

pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /snapshot/node_modules/@automapper/classes/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:294:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:641:9)
    at resolveExports (node:internal/modules/cjs/loader:591:36)
    at Module._findPath (node:internal/modules/cjs/loader:668:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1947:44)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/helpers:176:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v20.10.0

It seems to me that the fix is as simple as replacing "./" with just ".".

Models/DTOs/VMs

N/A

Mapping configuration

N/A

Steps to reproduce

Just open @automapper/classes on VSCode to get the aforementioned warning.

Expected behavior

The main export of @automapper/classes should be correctly identified when using pkg to generate single-executable Node binaries.

This is fixed by exporting ".", instead of "./", which is not a valid export path.

Screenshots

No response

Minimum reproduction code

No response

Package

Other package and its version

No response

AutoMapper version

8.8.0

Additional context

Linux Node v20

timonmasberg commented 8 months ago

idk if its related, but jest also starts throwing errors:

        node_modules/@automapper/classes/src/index.d.ts:1
           ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from './lib/classes';
                                                                                             ^^^^^^

           SyntaxError: Unexpected token 'export'

           > 1 | import { AutoMap } from '@automapper/classes';
               | ^

i tried different configs like adding the package to the transformIgnorePatterns or using jest with its esm configs, but i was not able to resolve the error on the new version.

gabrielkim13 commented 8 months ago

I'm not sure whether the jest error is related to this issue.

The change to @automapper/classes's package.json that causes the issue with pkg was made in a2dea1d (2023-03-10), while version 8.7.7 was released earlier (2022-10-25), so it's possible.

Someone else said that the error occurred in 8.7.7, but he/she removed the comment. Can you verify this @timonmasberg?

timonmasberg commented 8 months ago

Someone else said that the error occurred in 8.7.7, but he/she removed the comment. Can you verify this @timonmasberg?

I can not reproduce the error on 8.7.7, its probably not related to this issue but rather to this change

gabrielkim13 commented 8 months ago

Solved with #589.