1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-15 21:18:02 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Nuno Vieira
dbdf59c9df Merge 460473a87f into 0bfeb0e236 2024-07-23 22:44:32 +05:30
jbranchaud
0bfeb0e236 Add Avoid Conflicting Files as a Next.js TIL 2024-07-16 10:43:03 -05:00
Nuno Vieira
460473a87f Fix expected result of immutable remove operation 2020-07-30 14:32:08 +01:00
3 changed files with 40 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1434 TILs and counting..._
_1435 TILs and counting..._
---
@@ -634,6 +634,7 @@ _1434 TILs and counting..._
### Next.js
- [Avoid Conflicting Files](nextjs/avoid-conflicting-files.md)
- [Create Files And Directories For Dynamic Routes](nextjs/create-files-and-directories-for-dynamic-routes.md)
- [Define URL Redirects In The Next Config](nextjs/define-url-redirects-in-the-next-config.md)
- [Fetch Does Not Work In API Serverless Function](nextjs/fetch-does-not-work-in-api-serverless-function.md)

View File

@@ -15,10 +15,8 @@ const remove = (items,index) => {
};
const list = [1,2,3,4,5];
remove(list, 2);
// [1,2,3,4]
list
// [1,2,3,4,5]
remove(list, 2); // [1,2,4,5]
// list still [1,2,3,4,5]
```
It only took a couple lines of code and immutability is baked in.

View File

@@ -0,0 +1,36 @@
# Avoid Conflicting Files
When Next.js is bundling and building your project, it will get completely
tripped up by any instance of conflicting project files. What I mean by
conflicting project files are two JavaScript or TypeScript (or flavors of JSX
files) that would resolve to the same thing.
Here is one example where the extensions differ:
```
src/pages/welcome.tsx
src/pages/welcome.jsx
```
Here is another example where the paths differ but the bundled result would
conflict:
```
src/pages/welcome.tsx
src/pages/welcome/index.tsx
```
If you have any instances of these conflicting files, you'll be presented with
a beguiling and cryptic error message when trying to run the dev server.
```
TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:405:5)
at validateString (node:internal/validators:162:11)
at Object.relative (node:path:1191:5)
at Watchpack.<anonymous> (/my_app/node_modules/.pnpm/next@14.2.5_@babel+core@7.24.9_react-dom@18.3.1_react@18.3.1/node_modules/next/dist/server/lib/router-utils/setup-dev-bundler.js:381:55) {
code: 'ERR_INVALID_ARG_TYPE'
}
```
One of those files needs to go. Remove one of them and you'll be good to go.