vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.53k stars 26.82k forks source link

Turbopack tailwindcss error: Module not found #66602

Closed ndcunningham closed 1 month ago

ndcunningham commented 4 months ago

Link to the code that reproduces this issue

https://github.com/ndcunningham/nextjs-tw

To Reproduce

  1. Generate a new nextjs project using tailwindcss
  2. Install a tailwindcss plugin (I will use "prettier-plugin-tailwindcss") but any should really work
  3. Import that plugin inside the tailwind config to look something like this.
    
    const { join } = require('path');
    const prettierPlugin = require("prettier-plugin-tailwindcss");

module.exports = { content: [ join( __dirname, '{src,pages,components,app}/*/!(.stories|.spec).{ts,tsx,html}' ), ], theme: { extend: {}, }, "plugins": [prettierPlugin], }

4. run the dev server with `--turbo` 

Here is another example using Nx where the utility function is from Nx.
All that is required to reproduce it is importing the function. Consuming it does not seem to matter.
https://github.com/ndcunningham/nx-next-tailwind

This is probably related to: https://github.com/vercel/next.js/issues/64423

### Current vs. Expected behavior

## Current

After following these steps there should be module not found errors after compiling for example
```shell
 ⨯ ./node_modules/prettier/index.js:18428:31
Module not found
  18426 |                 paths: [dir]
  18427 |               });
> 18428 |               result.config = require(modulePath);
        |                               ^^^^^^^^^^^^^^^^^^^
  18429 |             }
  18430 |             if (typeof result.config !== "object") {
  18431 |               throw new TypeError(`Config is only allowed to be an object, but received ${typeof result.config} in "${result.filepath}"`);

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

Expected

There should be no issues as this works correctly without --turbo

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 21.7.1
  npm: 10.5.0
  Yarn: 1.22.17
  pnpm: 7.29.2
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I tested the reproduction with canary and it is also experiencing the same issues. Using nextjs version 14.1.4 also reproduces the same issues.

seung-juv commented 4 months ago

tailwind config is wrong.

There is no part in pretier-plugin-tailwindcss that modifies tailwind.config.js (https://github.com/tailwindlabs/prettier-plugin-tailwindcss)

tailwind.config.js

const { join } = require('path');
const prettierPlugin = require("prettier-plugin-tailwindcss");

module.exports = {
  content: [
    join(
      __dirname,
      '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}'
    ),
  ],
  theme: {
    extend: {},
  },
  // "plugins": [prettierPlugin], // <- Remove this line
};
ndcunningham commented 3 months ago

Even with that line removed, the same outcome persists. As long as it is imported, using --turbo will still result in an error.

seung-juv commented 3 months ago

@ndcunningham You're right, you should erase both.

tailwind.config.js

const { join } = require('path');
// const prettierPlugin = require("prettier-plugin-tailwindcss");

module.exports = {
  content: [
    join(
      __dirname,
      '{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}'
    ),
  ],
  theme: {
    extend: {},
  },
  // "plugins": [prettierPlugin],
};

That's not how it's used in official documents, so there's nothing to say about the error

jgalbsss commented 2 months ago

Could be related to https://github.com/vercel/next.js/issues/60363#issuecomment-1890480269

github-actions[bot] commented 1 month ago

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.