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/next importing ts file into next.config.ts file causing build to break #28960

Closed
1 of 4 tasks
DrewLandgraveCbsi opened this issue Nov 15, 2024 · 1 comment · Fixed by #29071
Closed
1 of 4 tasks
Assignees

Comments

@DrewLandgraveCbsi
Copy link

Current Behavior

When attempting to build a nextjs app and using typescript config files. If I import another typescript file (in my case a common next config from libs) I'm getting the following error

Cannot find file "../../libs/next-configs/src/lib/next-configs" with any of the following extensions: .js, .cjs, .mjs, .json

Error: Cannot find file "../../libs/next-configs/src/lib/next-configs" with any of the following extensions: .js, .cjs, .mjs, .json
    at /Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:167:19
    at Array.map (<anonymous>)
    at ensureFileExtensions (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:158:18)
    at doCollect (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:121:25)
    at getRelativeFilesToCopy (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:129:5)
    at createNextConfigFile (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:46:31)
    at buildExecutor (/Users/PROJECT/node_modules/@nx/next/src/executors/build/build.impl.js:78:60)
    at async promiseToIterator (/Users/PROJECT/node_modules/nx/src/command-line/run/run.js:36:11)
    at async getLastValueFromAsyncIterableIterator (/Users/PROJECT/node_modules/nx/src/utils/async-iterator.js:15:19)
    at async iteratorToProcessStatusCode (/Users/PROJECT/node_modules/nx/src/command-line/run/run.js:39:25)

Failing in my next.config.ts file here

import { nextSecurityConfigs } from '../../libs/next-configs/src/lib/next-configs';

If I go into node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js on line 157 I see const extensions = ['.js', '.cjs', '.mjs', '.json']; Adding ts to this array fixes the issue

On a separate note I had to import it like that because doing import { nextSecurityConfigs } from '@PROJECT/next-configs gave me a module not found error during the serve and build targets

Expected Behavior

I should be able to use typescript import files in typescript files

GitHub Repo

No response

Steps to Reproduce

  1. Create a new NextJs application
  2. Create a new lib with next configs
  3. Add a typescript file to the new lib
  4. Attempt to import the file in your next.config.ts file in your next application
  5. Run nx build on your application
  6. You should see the error

Nx Report

NX   Report complete - copy this into the issue template

Node           : 20.15.0
OS             : darwin-arm64
Native Target  : aarch64-macos
yarn           : 4.2.2

nx                 : 20.1.1
@nx/js             : 20.1.1
@nx/jest           : 20.1.1
@nx/eslint         : 20.1.1
@nx/workspace      : 20.1.1
@nx/cypress        : 20.1.1
@nx/devkit         : 20.1.1
@nx/esbuild        : 20.1.1
@nx/eslint-plugin  : 20.1.1
@nx/nest           : 20.1.1
@nx/next           : 20.1.1
@nx/node           : 20.1.1
@nx/plugin         : 20.1.1
@nx/react          : 20.1.1
@nx/rspack         : 20.1.1
@nx/storybook      : 20.1.1
@nx/vite           : 20.1.1
@nx/web            : 20.1.1
@nx/webpack        : 20.1.1
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/next/plugin
@nx/cypress/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/webpack/plugin
@nx/vite/plugin
@nx/storybook/plugin

Failure Logs

Cannot find file "../../libs/next-configs/src/lib/next-configs" with any of the following extensions: .js, .cjs, .mjs, .json

Error: Cannot find file "../../libs/next-configs/src/lib/next-configs" with any of the following extensions: .js, .cjs, .mjs, .json
    at /Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:167:19
    at Array.map (<anonymous>)
    at ensureFileExtensions (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:158:18)
    at doCollect (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:121:25)
    at getRelativeFilesToCopy (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:129:5)
    at createNextConfigFile (/Users/PROJECT/node_modules/@nx/next/src/executors/build/lib/create-next-config-file.js:46:31)
    at buildExecutor (/Users/PROJECT/node_modules/@nx/next/src/executors/build/build.impl.js:78:60)
    at async promiseToIterator (/Users/PROJECT/node_modules/nx/src/command-line/run/run.js:36:11)
    at async getLastValueFromAsyncIterableIterator (/Users/PROJECT/node_modules/nx/src/utils/async-iterator.js:15:19)
    at async iteratorToProcessStatusCode (/Users/PROJECT/node_modules/nx/src/command-line/run/run.js:39:25)

Package Manager Version

Yarn 4.2.2

Operating System

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

Additional Information

No response

@ndcunningham ndcunningham self-assigned this Nov 25, 2024
ndcunningham added a commit that referenced this issue Nov 27, 2024
<!-- 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 #28960
FrozenPandaz pushed a commit that referenced this issue Nov 28, 2024
<!-- 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 #28960

(cherry picked from commit 8eb6159)
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 Dec 28, 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.

2 participants