Skip to content

Problems with Next and internal libs #30714

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

Open
1 of 4 tasks
gperdomor opened this issue Apr 14, 2025 · 10 comments · May be fixed by #31323
Open
1 of 4 tasks

Problems with Next and internal libs #30714

gperdomor opened this issue Apr 14, 2025 · 10 comments · May be fixed by #31323
Assignees
Labels
priority: medium Medium Priority (not high, not low priority) scope: nextjs Issues related to NextJS support for Nx type: bug

Comments

@gperdomor
Copy link
Contributor

gperdomor commented Apr 14, 2025

Current Behavior

You can't use internal workspace libs in your next apps... The packages are not resolved

Expected Behavior

The apps should works as expected...

GitHub Repo

https://github.com/gperdomor/nx-next-issue

Steps to Reproduce

  1. Create an empty workspace
  2. Create a sample js library
  3. Create a next app
  4. Use the library inside your next app
  5. Run the app and open a page... Is working as expected
  6. Update next to latest 15.3.0 version (also in package.json from the app folder)
  7. Run the app again and open a page... Make sure that runs with next 15.3.0, if not please remove .next folder and node_modules inside your app folder.
  8. You will get something like this:
Image

Nx Report

nx report

 NX   Report complete - copy this into the issue template

Node           : 22.14.0
OS             : darwin-x64
Native Target  : x86_64-macos
npm            : 11.3.0

nx (global)            : 20.8.0
nx                     : 20.8.0
@nx/js                 : 20.8.0
@nx/eslint             : 20.8.0
@nx/workspace          : 20.8.0
@nx/devkit             : 20.8.0
@nx/eslint-plugin      : 20.8.0
@nx/module-federation  : 20.8.0
@nx/next               : 20.8.0
@nx/react              : 20.8.0
@nx/vite               : 20.8.0
@nx/web                : 20.8.0
@nx/webpack            : 20.8.0
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/vite/plugin
@nx/eslint/plugin
@nx/next/plugin
---------------------------------------
Cache Usage: 0.00 B / 93.15 GB

Failure Logs

nx run website:dev --turbo

> next dev --turbo

   ▲ Next.js 15.3.0 (Turbopack)
   - Local:        http://localhost:3000
   - Network:      http://192.168.1.93:3000

 ✓ Starting...
 ✓ Ready in 2s
 ○ Compiling / ...
 ✓ Compiled / in 1082ms
 ⨯ ./packages/sample-lib/src/index.ts:1:1
Module not found: Can't resolve './lib/sample-lib.js'
> 1 | export * from './lib/sample-lib.js';
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 |



https://nextjs.org/docs/messages/module-not-found



./apps/website/src/app/page.tsx:1:1
Export sampleLib doesn't exist in target module
> 1 | import { sampleLib } from '@sandbox/sample-lib';
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 | import styles from './page.module.css';
  3 |
  4 | export default function Index() {

The export sampleLib was not found in module [project]/packages/sample-lib/src/index.ts [app-rsc] (ecmascript) <exports>.
The module has no exports at all.
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.


 ○ Compiling /_error ...
 ✓ Compiled /_error in 1073ms
 GET / 500 in 2421ms

n^C

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Successfully ran target dev for project website

Package Manager Version

npm 11.3.0

Operating System

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

Additional Information

No response

@FrozenPandaz FrozenPandaz added scope: nextjs Issues related to NextJS support for Nx priority: medium Medium Priority (not high, not low priority) labels Apr 14, 2025
@ianldgs
Copy link
Contributor

ianldgs commented Apr 15, 2025

@mj-meyer
Copy link

can confirm, I'm running into the same issue

@gperdomor
Copy link
Contributor Author

Any update or workaround for this? 👀

@gperdomor
Copy link
Contributor Author

@mj-meyer did you find a solution for this?...

@gperdomor gperdomor changed the title Problems witn next 15.3 and internal libs Problems with next and internal libs May 23, 2025
@gperdomor gperdomor changed the title Problems with next and internal libs Problems with Next and internal libs May 23, 2025
@gperdomor
Copy link
Contributor Author

Hi @ndcunningham, did you was able to take a look at this?... At the end also occurs in Next 15.2 too, not in Next 15.3 :(

@ndcunningham
Copy link
Contributor

ndcunningham commented May 23, 2025

Hey, I took a look and the problem here is Next.js by default doesn't support esm libs extensions import as .js.

A workaround is to just change your library export from .js to .ts and it should work.
Additionally, you can configure your next.config.js to resolve the .js extension to also be .ts.

const nextConfig = {
  webpack: (config) => {
    config.resolve.extensionAlias = {
      '.js': ['.js', '.ts', '.tsx'],
    };
    return config;
  },
  nx: {
    // Set this to true if you would like to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: false,
  },
};

A fix is coming shortly!

@gperdomor
Copy link
Contributor Author

@ndcunningham there is something else happening...

If you create a lib, publish the package, and install the package in a new next app in another Nx workspace or created with npx create-next-app, is not working...

The problem is the "development": "./src/index.ts", line inside the package.json exports...

Removing that line make the library works in external next apps

@ndcunningham
Copy link
Contributor

ndcunningham commented May 24, 2025

@gperdomor can you create a new issue for this so that it can be tracked?
Be sure to include the reproduction steps as well thanks!

@gperdomor
Copy link
Contributor Author

gperdomor commented May 25, 2025

@ndcunningham this is the new issue #31332 to track the new cases, let me know if you need something else 🙏🏻

@ndcunningham
Copy link
Contributor

After looking further into this I think there are two issues related to both Webpack and Turbopack.
The webpack issue will be fixed with the PR but serving using turbopack --turbo still does not work.

I think that this issue is related to turbopack as the configuration should be the same as webpack.
I found a few issues on Vercel's github here is one: vercel/next.js#69426 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium Medium Priority (not high, not low priority) scope: nextjs Issues related to NextJS support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants