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

Open
1 of 4 tasks
DrewLandgraveCbsi opened this issue Nov 15, 2024 · 0 comments
Open
1 of 4 tasks

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant