tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
553 stars 20 forks source link

Unable to resolve nextjs-routes/config though working #163

Closed mehdimahmoudi closed 1 year ago

mehdimahmoudi commented 1 year ago

Hi, First things first, thank you for this great tool! Amazing and accurate work.

I'm facing a dependency resolution issue that's keeping me from building the project without having to comment / disable the nextjs-routes require line.

Important to note that although the module is not resolved and ESLinting showing an error, it still works perfectly and generates routes at the right location as expected.

Any clue?

Thanks!

image
tatethurston commented 1 year ago

@mehdimahmoudi could you share the error you’re encountering?

mehdimahmoudi commented 1 year ago

@tatethurston

I get this linting error: Unable to resolve path to module 'nextjs-routes/config' also keeping me from building the app.

image

But I don't think it's just a linting because other requires work well.

Here's my next.config.jsfile

// @ts-check

// @TODO: Cannot be imported or built with
const nextRoutes = require('nextjs-routes/config');

const withRoutes = nextRoutes();
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});
const { i18n } = require('./next-i18next.config');

// Route typing
const withRoutes = nextRoutes({ outDir: 'src/types/routes', cwd: __dirname });

/**
 * @type {import('next').NextConfig}
 **/
const baseConfig = withBundleAnalyzer({
  reactStrictMode: false,
  i18n,
  eslint: {
    ignoreDuringBuilds: true,
  },
});

module.exports = withRoutes(baseConfig);

Note: I'm using pnpm

Thanks

tatethurston commented 1 year ago

@mehdimahmoudi Do you encounter any typescript errors? Eg running tsc —noEmit?

Also, could you update your ESLint dependencies to make sure they’re not outdated

mehdimahmoudi commented 1 year ago

@tatethurston

Just updated to ESLInt 8.42 (yesterday 8.41

npx tsc --noEmit still gives:

image

tatethurston commented 1 year ago

@mehdimahmoudi I believe this is an issue with your local dependencies and not this library. I'm sorry for the unsatisfying answer.

To debug this on your end, you could start by copying one of the examples -- like the typescript example -- locally and seeing if you still encounter the error (you shouldn't). From there you can compare your dependencies to the example project dependencies to narrow it down.