-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
Check for .json file extension before JSON parse. Was throwing when r… #601
Conversation
|
||
cache[f] = component | ||
return component | ||
if (f.slice(-5) === '.json') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is always .json
? @arunoda
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But actually, SyntaxError: Unexpected token m in JSON at position 0
this error looks like trying to parse a JS file (module.exports =....
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have .js
as well. In order to support dist
. Loading SSR files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! wait. But for here, it's always .json
.
If there's no .json
file, we need to throw an error.
Then I think we don't need a change here.
Just tested |
@@ -12,11 +12,15 @@ async function readPage (path) { | |||
return cache[f] | |||
} | |||
|
|||
const source = await fs.readFile(f, 'utf8') | |||
const { component } = JSON.parse(source) | |||
let content = await fs.readFile(f, 'utf8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msand Would you mind removing all the changes done to this page.
We always need to read .json
files so if there's no .json
file, that's an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I figured as much, should've made a separate pr to begin with. Thanks
Took this PR with #611 |
…eading js files. Related to #597