elmasse / nextein-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught (in promise) TypeError: fs.readdirSync is not a function

stickhandle opened this issue · comments

Running a fresh install (clone) with npm run dev , I see the following in the console (for url http://localhost:3000):

Uncaught (in promise) TypeError: fs.readdirSync is not a function
    at GlobSync.webpackJsonp../node_modules/glob/sync.js.GlobSync._readdir (sync.js:288)
    at GlobSync.webpackJsonp../node_modules/glob/sync.js.GlobSync._processGlobStar (sync.js:350)
    at GlobSync.webpackJsonp../node_modules/glob/sync.js.GlobSync._process (sync.js:130)
    at new GlobSync (sync.js:48)
    at Function.globSync [as sync] (sync.js:26)
    at loadEntries (load.js:21)
    at ProxyComponent.componentDidMount (link.js:72)
    at ProxyComponent.componentDidMount (react-hot-loader.development.js:531)
    at commitLifeCycles (react-dom.development.js:9784)
    at commitAllLifeCycles (react-dom.development.js:11455)

On browser (Chrome) page refresh, the page returns correctly.
When clicking any link (in header, like http://localhost:3000/all-posts) page returns as:

fs.readdirSync is not a function
TypeError: fs.readdirSync is not a function
    at GlobSync.webpackJsonp../node_modules/glob/sync.js.GlobSync._readdir (node_modules/glob/sync.js:288:0)
    at GlobSync.webpackJsonp../node_modules/glob/sync.js.GlobSync._processGlobStar (node_modules/glob/sync.js:350:0)
    at GlobSync.webpackJsonp../node_modules/glob/sync.js.GlobSync._process (node_modules/glob/sync.js:130:0)
    at new GlobSync (node_modules/glob/sync.js:48:0)
    at Function.globSync [as sync] (node_modules/glob/sync.js:26:0)
    at loadEntries (node_modules/nextein/dist/entries/load.js:21:0)
    at Function.getInitialProps (node_modules/nextein/dist/components/posts.js:88:0)
    at _callee$ (node_modules/next/dist/lib/utils.js:111:0)
    at tryCatch (node_modules/regenerator-runtime/runtime.js:62:0)
    at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:0)

Again, on refresh, the page displays correctly.

EDIT: Note the issue presents for npm run export/http-serve scenario as well

Hey @stickhandle thanks for reporting this. Could you please tell me which env are you running this? Like node version, Chrome version, OS, etc?

I tried a fresh new clone, npm i and npm run dev seems to work fine. Also, running a npm run exports it runs successfully. I'm running node 9.3 on Mac OS X 10.13.4

 DONE  Compiled successfully in 385ms                                                                           08:02:07

^C⏎
➜  nextein-example git:(master) npm run export

> nextein-example@1.0.0 export /Users/elmasse/tmp/nextein-example
> nextein build && nextein export

> using build directory: /Users/elmasse/tmp/nextein-example/.next
  copying "static" directory
  copying "static build" directory
> exporting path: /post/first-post
> exporting path: /post/second-post.html
> exporting path: /cars/bmw
> exporting path: /cars/tesla
> exporting path: /food/pizza
> exporting path: /food/taco
> exporting path: /sub-section/sub-sub-section/sub-one
> exporting path: /home/third-post
> exporting path: /uncategorize
> exporting path: /
> exporting path: /all-posts
> exporting path: /sub-section
> exporting path: /tags
> exporting path: /cars
> exporting path: /food

➜  nextein-example git:(master)

Thanks for checking in to this @elmasse.
Build and export runs successfully for me too. It's a runtime issue.
Node: version v9.11.1
OS: Windows 10 64-bit v 1709 build 16229.431 (which is latest)
Chrome: Version 66.0.3359.181 (Official Build) (64-bit) (which is latest)
Issue also happens in Firefox Quantum 60.0

Ok, seems to be a Windows issue. I'll fire up a Windows 10 VM and give it a try. fs.readFileSync should not be executed on the client nor exported code. I have a webpack configuration that replaces the load.js and injects the right one for each client or exported envs.

Thanks again for your time to report this!

In case it helps, Firefox gives a little different info.
On npm run dev, when clicking a link it return page as:

fs.readdirSync is not a function

./node_modules/glob/sync.js/</GlobSync.prototype._readdir@http://localhost:3000/_next/-/page/all-posts.js:12974:38
./node_modules/glob/sync.js/</GlobSync.prototype._processGlobStar@http://localhost:3000/_next/-/page/all-posts.js:13036:17
./node_modules/glob/sync.js/</GlobSync.prototype._process@http://localhost:3000/_next/-/page/all-posts.js:12816:5
GlobSync@http://localhost:3000/_next/-/page/all-posts.js:12734:5
globSync@http://localhost:3000/_next/-/page/all-posts.js:12712:10
loadEntries@http://localhost:3000/_next/-/page/all-posts.js:30339:15
getInitialProps@http://localhost:3000/_next/-/page/all-posts.js:30251:33
_callee$@http://localhost:3000/_next/static/commons/main.js:9127:20
tryCatch@http://localhost:3000/_next/static/commons/main.js:31483:37
invoke@http://localhost:3000/_next/static/commons/main.js:31717:22
defineIteratorMethods/</prototype[method]@http://localhost:3000/_next/static/commons/main.js:31535:16
step@http://localhost:3000/_next/static/commons/main.js:166:22
_next@http://localhost:3000/_next/static/commons/main.js:181:9
_asyncToGenerator/</<@http://localhost:3000/_next/static/commons/main.js:188:7
Promise@http://localhost:3000/_next/static/commons/main.js:3255:7
_asyncToGenerator/<@http://localhost:3000/_next/static/commons/main.js:161:12
loadGetInitialProps@http://localhost:3000/_next/static/commons/main.js:9106:10
_callee$@http://localhost:3000/_next/-/page/_app.js:148:25
tryCatch@http://localhost:3000/_next/static/commons/main.js:31483:37
invoke@http://localhost:3000/_next/static/commons/main.js:31717:22
defineIteratorMethods/</prototype[method]@http://localhost:3000/_next/static/commons/main.js:31535:16
step@http://localhost:3000/_next/static/commons/main.js:166:22
_next@http://localhost:3000/_next/static/commons/main.js:181:9
_asyncToGenerator/</<@http://localhost:3000/_next/static/commons/main.js:188:7
Promise@http://localhost:3000/_next/static/commons/main.js:3255:7
_asyncToGenerator/<@http://localhost:3000/_next/static/commons/main.js:161:12
getInitialProps@http://localhost:3000/_next/-/page/_app.js:165:16
_callee$@http://localhost:3000/_next/static/commons/main.js:9127:20
tryCatch@http://localhost:3000/_next/static/commons/main.js:31483:37
invoke@http://localhost:3000/_next/static/commons/main.js:31717:22
defineIteratorMethods/</prototype[method]@http://localhost:3000/_next/static/commons/main.js:31535:16
step@http://localhost:3000/_next/static/commons/main.js:166:22
_next@http://localhost:3000/_next/static/commons/main.js:181:9
_asyncToGenerator/</<@http://localhost:3000/_next/static/commons/main.js:188:7
Promise@http://localhost:3000/_next/static/commons/main.js:3255:7
_asyncToGenerator/<@http://localhost:3000/_next/static/commons/main.js:161:12
_loadGetInitialProps@http://localhost:3000/_next/static/commons/main.js:9159:10
loadGetInitialProps@http://localhost:3000/_next/static/commons/main.js:9106:10
_callee7$@http://localhost:3000/_next/static/commons/main.js:8642:25
tryCatch@http://localhost:3000/_next/static/commons/main.js:31483:37
invoke@http://localhost:3000/_next/static/commons/main.js:31717:22
defineIteratorMethods/</prototype[method]@http://localhost:3000/_next/static/commons/main.js:31535:16
step@http://localhost:3000/_next/static/commons/main.js:166:22
_next@http://localhost:3000/_next/static/commons/main.js:181:9
_asyncToGenerator/</<@http://localhost:3000/_next/static/commons/main.js:188:7
Promise@http://localhost:3000/_next/static/commons/main.js:3255:7
_asyncToGenerator/<@http://localhost:3000/_next/static/commons/main.js:161:12
getInitialProps@http://localhost:3000/_next/static/commons/main.js:8676:16
_callee4$@http://localhost:3000/_next/static/commons/main.js:8393:24
tryCatch@http://localhost:3000/_next/static/commons/main.js:31483:37
invoke@http://localhost:3000/_next/static/commons/main.js:31717:22
defineIteratorMethods/</prototype[method]@http://localhost:3000/_next/static/commons/main.js:31535:16
step@http://localhost:3000/_next/static/commons/main.js:166:22
_next@http://localhost:3000/_next/static/commons/main.js:181:9
run@http://localhost:3000/_next/static/commons/main.js:3153:22
notify/<@http://localhost:3000/_next/static/commons/main.js:3170:30
flush@http://localhost:3000/_next/static/commons/main.js:1960:9

And while running as http-serve on the out folder, the console output:

r.readdirSync is not a function
module.exports</</m.prototype._readdir@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:141282
module.exports</</m.prototype._processGlobStar@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:142020
module.exports</</m.prototype._process@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:139812
m@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:139087
d@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:138693
module.exports</</t.default@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:20:3857
value@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:128949
e/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:18867
v@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15401
_/o._invoke</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15191
N/</e[t]@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15577
s@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41885
u@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41978
module.exports</e.exports/</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:42017
D@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:20345
module.exports</e.exports/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41820
module.exports</</t.loadGetInitialProps@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:18362
e/<@http://127.0.0.1:8080/_next/60799b72-5df9-4a6b-b4ac-95b040fef74d/page/_app.js:1:1344
v@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15401
_/o._invoke</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15191
N/</e[t]@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15577
s@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41885
u@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41978
module.exports</e.exports/</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:42017
D@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:20345
module.exports</e.exports/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41820
module.exports</<.page<[534]/_</<.value<@http://127.0.0.1:8080/_next/60799b72-5df9-4a6b-b4ac-95b040fef74d/page/_app.js:1:1495
e/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:18867
v@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15401
_/o._invoke</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15191
N/</e[t]@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15577
s@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41885
u@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41978
module.exports</e.exports/</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:42017
D@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:20345
module.exports</e.exports/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41820
c@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:18651
module.exports</</t.loadGetInitialProps@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:18362
e/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:109722
v@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15401
_/o._invoke</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15191
N/</e[t]@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15577
s@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41885
u@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41978
module.exports</e.exports/</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:42017
D@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:20345
module.exports</e.exports/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41820
module.exports</_</<.value<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:110063
e/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:49:107193
v@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15401
_/o._invoke</<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15191
N/</e[t]@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:15577
s@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41885
u@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:9:41978
a@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:19256
R/<@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:19401
c@http://127.0.0.1:8080/_next/static/commons/main-a8a5a33c749164aa345a.js:41:22217

Hi @stickhandle,

Could you try the latest changes? It should install nextein v1.3.1 which should solve this problem.

Looks good @elmasse . Great work on the quick turnaround. And thanks for nextein.

Thank you for taking the time to report the issue! And thanks for giving nextein a chance!