Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@nx/js:tsc fails to declare proper export on 'index' file in 'additionalEntryPoints' #23519

Closed
1 of 4 tasks
shlomiassaf opened this issue May 18, 2024 · 1 comment · Fixed by #27112
Closed
1 of 4 tasks

Comments

@shlomiassaf
Copy link

shlomiassaf commented May 18, 2024

Current Behavior

Declaring barrel additional export does not declare a barrel reference in exports:

{
    "package": {
      "executor": "@nx/js:tsc",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/libs/my-lib",
        "tsConfig": "libs/my-lib/tsconfig.lib.json",
        "main": "libs/my-lib/src/index.ts",
        "assets": ["libs/my-lib/*.md"],
        "srcRootForCompilationRoot": "libs/my-lib",
        "additionalEntryPoints": [
          "libs/my-lib/tasks/index.ts"
        ],
        "generateExportsField": true
      }
    }
}

Yields the following exports, in package.json:

{
  "exports": {
    "./package.json": "./package.json",
    ".": "./src/index.js",
    "./tasks/index": "./tasks/index.js"
  }
}

The additional export was libs/my-lib/tasks/index.ts and the exported reference was "./tasks/index": "./tasks/index.js"

This will work with import { something } from 'my-lib/tasks/index'
It will not work with import { something } from 'my-lib/tasks'

Expected Behavior

When index is exported, also export a barrel reference.

{
  "exports": {
    "./package.json": "./package.json",
    ".": "./src/index.js",
    "./tasks/index": "./tasks/index.js",
    "./tasks": "./tasks/index.js"
  }
}

Around here:

const isJsFile = jsRegex.test(fileExt);

GitHub Repo

No response

Steps to Reproduce

Nx Report

Node   : 18.18.2
OS     : darwin-arm64
yarn   : 1.22.18

nx (global)        : 19.0.2
nx                 : 19.0.2
@nx/js             : 19.0.2
@nx/jest           : 19.0.2
@nx/linter         : 19.0.2
@nx/eslint         : 19.0.2
@nx/workspace      : 19.0.2
@nx/devkit         : 19.0.2
@nx/eslint-plugin  : 19.0.2
@nx/node           : 19.0.2
@nx/plugin         : 19.0.2
@nx/react          : 19.0.2
@nrwl/tao          : 19.0.2
@nx/web            : 19.0.2
@nx/webpack        : 19.0.2
typescript         : 5.4.5
---------------------------------------
Local workspace plugins:
         @pebula/nx-api-extractor
         @pebula/nx-build-pipe

Failure Logs

When running code that use the packaged & published library I get the following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './tasks' is not defined by "exports" in /Users/XXXX/project/test/node_modules/my-lib/package.json
    at new NodeError (node:internal/errors:405:5)
    at exportsNotFound (node:internal/modules/esm/resolve:362:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:698:9)
    at resolveExports (node:internal/modules/cjs/loader:567:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:636:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1063:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue (/Users/XXXX/project/test/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._resolveFilename (/Users/XXXX/project/test/node_modules/tsconfig-paths/lib/register.js:75:40)
    at Function.Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

I assume its related to my setup, maybe the sourcemap pipeline, but this should be exported as a barrel regardless.

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

FrozenPandaz pushed a commit that referenced this issue Jul 30, 2024
… for barrel files (#27112)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23519

(cherry picked from commit 484e9b1)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants