You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a file called _document in any folder outside of pages, the rule will crash:
create: function(context){return{ImportDeclaration(node){if(node.source.value!=='next/document'){return}constpage=context.getFilename().split('pages')[1]// <--- crashesconst{ name, dir }=path.parse(page)
context.getFilename() in my case is C:\Users\gerr.it\Desktop\dev\personal-react-boilerplate\src\client\__tests__\_document.test.tsx
error with stack trace:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:329:5)
at validateString (node:internal/validators:129:11)
at Object.parse (node:path:853:5)
at ImportDeclaration (C:\Users\gerr.it\Desktop\dev\personal-react-boilerplate\node_modules\@next\eslint-plugin-next\lib\rules\no-document-import-in-page.js:20:36)
Proposed solution:
create: function(context){return{ImportDeclaration(node){if(node.source.value!=='next/document'){return;}constpage=context.getFilename().split('pages')[1];if(!page){return;}const{ name, dir }=path.parse(page);if(name.startsWith('_document')||name.includes('.test')||(dir==='/_document'&&name==='index')){return;}
Expected Behavior
works as expected
To Reproduce
have an import on anything from next/document outside of the pages folder should crash
The text was updated successfully, but these errors were encountered:
Fixes#28030Fixes#28169
## Bug
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
vercel
locked as resolved and limited conversation to collaborators
Jan 27, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Next.js are you using?
11.1.0
What version of Node.js are you using?
latest
What browser are you using?
irrelevant
What operating system are you using?
win
How are you deploying your application?
irrelevant
Describe the Bug
Given a file called
_document
in any folder outside ofpages
, the rule will crash:context.getFilename()
in my case isC:\Users\gerr.it\Desktop\dev\personal-react-boilerplate\src\client\__tests__\_document.test.tsx
error with stack trace:
Proposed solution:
Expected Behavior
works as expected
To Reproduce
have an import on anything from
next/document
outside of thepages
folder should crashThe text was updated successfully, but these errors were encountered: