opennextjs-netlify: Markdown files cannot be found in netlify function environment
Hi. First of all, Thanks for the plugin.
I am getting errors with my markdown blog. Pages and components seem to be working perfectly (tested with sample). but not working with the markdown directory. It’s giving me an error related to my file location.
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error: ENOENT: no such file or directory, scandir '/var/task/contents/blog'",
"trace": [
"Runtime.UnhandledPromiseRejection: Error: ENOENT: no such file or directory, scandir '/var/task/contents/blog'",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:314:20)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}
Deploy Log
5:36:18 PM: Build ready to start
5:36:20 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
5:36:20 PM: build-image tag: v3.6.0
5:36:20 PM: buildbot version: 94ed42511c4e70547a960237db686b74875fef2d
5:36:20 PM: Fetching cached dependencies
5:36:20 PM: Starting to download cache of 275.3KB
5:36:20 PM: Finished downloading cache in 77.823649ms
5:36:20 PM: Starting to extract cache
5:36:20 PM: Finished extracting cache in 14.676215ms
5:36:20 PM: Finished fetching cache in 92.929933ms
5:36:20 PM: Starting to prepare the repo for build
5:36:21 PM: Preparing Git Reference refs/heads/main
5:36:23 PM: Starting build script
5:36:23 PM: Installing dependencies
5:36:23 PM: Python version set to 2.7
5:36:24 PM: v12.18.0 is already installed.
5:36:25 PM: Now using node v12.18.0 (npm v6.14.4)
5:36:25 PM: Started restoring cached build plugins
5:36:25 PM: Finished restoring cached build plugins
5:36:25 PM: Attempting ruby version 2.7.1, read from environment
5:36:27 PM: Using ruby version 2.7.1
5:36:27 PM: Using PHP version 5.6
5:36:27 PM: Started restoring cached node modules
5:36:27 PM: Finished restoring cached node modules
5:36:27 PM: Started restoring cached yarn cache
5:36:27 PM: Finished restoring cached yarn cache
5:36:27 PM: Installing yarn at version 1.22.4
5:36:27 PM: Installing Yarn!
5:36:27 PM: > Downloading tarball...
5:36:27 PM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.OaqmPaAqag
5:36:27 PM: % Total % Received % Xferd Average Speed Time Time Time Current
5:36:27 PM: Dload Upload Total Spent Left Speed
5:36:28 PM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
5:36:28 PM: 100 80 100 80 0 0 241 0 --:--:-- --:--:-- --:--:-- 241
5:36:28 PM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
5:36:28 PM: 100 93 100 93 0 0 138 0 --:--:-- --:--:-- --:--:-- 3444
5:36:28 PM: 100 643 100 643 0 0 620 0 0:00:01 0:00:01 --:--:-- 620
5:36:29 PM: 100 1215k 100 1215k 0 0 802k 0 0:00:01 0:00:01 --:--:-- 802k
5:36:29 PM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.OaqmPaAqag.asc
5:36:29 PM: 100 84 100 84 0 0 3073 0 --:--:-- --:--:-- --:--:-- 3073
5:36:29 PM: 100 97 100 97 0 0 1764 0 --:--:-- --:--:-- --:--:-- 1764
5:36:29 PM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
5:36:29 PM: 100 647 100 647 0 0 3829 0 --:--:-- --:--:-- --:--:-- 631k
5:36:29 PM: 100 1028 100 1028 0 0 4923 0 --:--:-- --:--:-- --:--:-- 4923
5:36:29 PM: > Verifying integrity...
5:36:29 PM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
5:36:29 PM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
5:36:29 PM: gpg: WARNING: This key is not certified with a trusted signature!
5:36:29 PM: gpg: There is no indication that the signature belongs to the owner.
5:36:29 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
5:36:29 PM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
5:36:29 PM: > GPG signature looks good
5:36:29 PM: > Extracting to ~/.yarn...
5:36:29 PM: > Adding to $PATH...
5:36:30 PM: > Successfully installed Yarn 1.22.4! Please open another terminal where the `yarn` command will now be available.
5:36:30 PM: Installing NPM modules using Yarn version 1.22.4
5:36:30 PM: yarn install v1.22.4
5:36:30 PM: [1/4] Resolving packages...
5:36:31 PM: [2/4] Fetching packages...
5:36:42 PM: info fsevents@2.1.3: The platform "linux" is incompatible with this module.
5:36:42 PM: info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
5:36:42 PM: info fsevents@1.2.13: The platform "linux" is incompatible with this module.
5:36:42 PM: info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
5:36:42 PM: [3/4] Linking dependencies...
5:36:46 PM: [4/4] Building fresh packages...
5:36:50 PM: Done in 19.73s.
5:36:50 PM: NPM modules installed using Yarn
5:36:50 PM: Started restoring cached go cache
5:36:50 PM: Finished restoring cached go cache
5:36:50 PM: go version go1.14.4 linux/amd64
5:36:50 PM: go version go1.14.4 linux/amd64
5:36:50 PM: Installing missing commands
5:36:50 PM: Verify run directory
5:36:52 PM:
5:36:52 PM: ────────────────────────────────────────────────────────────────
5:36:52 PM: Netlify Build
5:36:52 PM: ────────────────────────────────────────────────────────────────
5:36:52 PM:
5:36:52 PM: ❯ Version
5:36:52 PM: @netlify/build 7.0.0
5:36:52 PM:
5:36:52 PM: ❯ Flags
5:36:52 PM: deployId: 5fd5fcb20cd506b6ee26c0bc
5:36:52 PM: mode: buildbot
5:36:52 PM:
5:36:52 PM: ❯ Current directory
5:36:52 PM: /opt/build/repo
5:36:52 PM:
5:36:52 PM: ❯ Config file
5:36:52 PM: No config file was defined: using default values.
5:36:52 PM:
5:36:52 PM: ❯ Context
5:36:52 PM: production
5:36:52 PM:
5:36:52 PM: ❯ Installing plugins
5:36:52 PM: - @netlify/plugin-nextjs@1.0.2
5:37:25 PM:
5:37:25 PM: ❯ Loading plugins
5:37:25 PM: - @netlify/plugin-nextjs@1.0.2 from Netlify app
5:37:26 PM:
5:37:26 PM: ────────────────────────────────────────────────────────────────
5:37:26 PM: 1. onPreBuild command from @netlify/plugin-nextjs
5:37:26 PM: ────────────────────────────────────────────────────────────────
5:37:26 PM:
5:37:26 PM: ** Adding next.config.js with target set to 'serverless' **
5:37:26 PM:
5:37:26 PM: (@netlify/plugin-nextjs onPreBuild completed in 10ms)
5:37:26 PM:
5:37:26 PM: ────────────────────────────────────────────────────────────────
5:37:26 PM: 2. Build command from Netlify app
5:37:26 PM: ────────────────────────────────────────────────────────────────
5:37:26 PM:
5:37:26 PM: $ yarn build
5:37:26 PM: yarn run v1.22.4
5:37:26 PM: $ next build
5:37:27 PM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://err.sh/next.js/no-cache
5:37:27 PM: info - Creating an optimized production build...
5:37:51 PM: warn - Compiled with warnings
5:37:51 PM: ./node_modules/next/dist/next-server/server/load-components.js
5:37:51 PM: Critical dependency: the request of a dependency is an expression
5:37:51 PM: ./node_modules/next/dist/next-server/server/load-components.js
5:37:51 PM: Critical dependency: the request of a dependency is an expression
5:37:51 PM: ./node_modules/next/dist/next-server/server/require.js
5:37:51 PM: Critical dependency: the request of a dependency is an expression
5:37:51 PM: ./node_modules/next/dist/next-server/server/require.js
5:37:51 PM: Critical dependency: the request of a dependency is an expression
5:37:51 PM: ./node_modules/next/dist/next-server/server/require.js
5:37:51 PM: Critical dependency: the request of a dependency is an expression
5:37:51 PM: ./node_modules/next/node_modules/node-fetch/lib/index.js
5:37:51 PM: Module not found: Can't resolve 'encoding' in '/opt/build/repo/node_modules/next/node_modules/node-fetch/lib'
5:37:51 PM: info - Collecting page data...
5:37:52 PM: info - Generating static pages (0/4)
5:37:53 PM: info - Generating static pages (1/4)
5:37:53 PM: info - Generating static pages (2/4)
5:37:53 PM: info - Generating static pages (3/4)
5:37:53 PM: info - Generating static pages (4/4)
5:37:53 PM: info - Finalizing page optimization...
5:37:53 PM: Page Size First Load JS
5:37:53 PM: ┌ ● / (ISR: 1 Seconds) 1.97 kB 64.3 kB
5:37:53 PM: ├ /_app 0 B 62.3 kB
5:37:53 PM: ├ ○ /404 3.01 kB 65.4 kB
5:37:53 PM: ├ λ /api/hello 0 B 62.3 kB
5:37:53 PM: └ ● /blog/[id] 1.94 kB 64.3 kB
5:37:53 PM: ├ /blog/static-site-generation
5:37:53 PM: └ /blog/test-post
5:37:53 PM: + First Load JS shared by all 62.3 kB
5:37:53 PM: ├ chunks/commons.40559a.js 12.8 kB
5:37:53 PM: ├ chunks/framework.ef157c.js 41.8 kB
5:37:53 PM: ├ chunks/main.c60f4c.js 6.54 kB
5:37:53 PM: ├ chunks/pages/_app.e774f4.js 526 B
5:37:53 PM: ├ chunks/webpack.e06743.js 751 B
5:37:53 PM: └ css/6fcf17ab8077bd559672.css 2.31 kB
5:37:53 PM: λ (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps)
5:37:53 PM: ○ (Static) automatically rendered as static HTML (uses no initial props)
5:37:53 PM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
5:37:53 PM: (ISR) incremental static regeneration (uses revalidate in getStaticProps)
5:37:53 PM: Done in 26.75s.
5:37:53 PM:
5:37:53 PM: (build.command completed in 27s)
5:37:53 PM:
5:37:53 PM: ────────────────────────────────────────────────────────────────
5:37:53 PM: 3. onBuild command from @netlify/plugin-nextjs
5:37:53 PM: ────────────────────────────────────────────────────────────────
5:37:53 PM:
5:37:53 PM: ** Running Next on Netlify package **
5:37:53 PM: 🚀 Next on Netlify 🚀
5:37:53 PM: Functions directory: netlify-automatic-functions
5:37:53 PM: Publish directory: /opt/build/repo
5:37:53 PM: Make sure these are set in your netlify.toml file.
5:37:53 PM: 🌍️ Copying public/ folder to /opt/build/repo
5:37:53 PM: 💼 Copying static NextJS assets to /opt/build/repo
5:37:53 PM: 💫 Setting up API endpoints as Netlify Functions in netlify-automatic-functions
5:37:53 PM: 💫 Setting up pages with getInitialProps as Netlify Functions in netlify-automatic-functions
5:37:53 PM: 💫 Setting up pages with getServerSideProps as Netlify Functions in netlify-automatic-functions
5:37:53 PM: 🔥 Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo
5:37:53 PM: 💫 Setting up pages with getStaticProps and fallback: true as Netlify Functions in netlify-automatic-functions
5:37:53 PM: 💫 Setting up pages with getStaticProps and revalidation interval as Netlify Functions in netlify-automatic-functions
5:37:53 PM: 🔥 Copying pre-rendered pages without props to /opt/build/repo
5:37:53 PM: 🔀 Setting up redirects
5:37:53 PM:
5:37:53 PM: (@netlify/plugin-nextjs onBuild completed in 167ms)
5:37:53 PM:
5:37:53 PM: ────────────────────────────────────────────────────────────────
5:37:53 PM: 4. Functions bundling
5:37:53 PM: ────────────────────────────────────────────────────────────────
5:37:53 PM:
5:37:53 PM: Packaging Functions from netlify-automatic-functions directory:
5:37:53 PM: - next_api_hello/next_api_hello.js
5:37:53 PM: - next_blog_id/next_blog_id.js
5:37:53 PM: - next_index/next_index.js
5:38:05 PM:
5:38:05 PM: (Functions bundling completed in 11.9s)
5:38:05 PM:
5:38:05 PM: ────────────────────────────────────────────────────────────────
5:38:05 PM: Netlify Build Complete
5:38:05 PM: ────────────────────────────────────────────────────────────────
5:38:05 PM:
5:38:05 PM: (Netlify Build completed in 1m 12.9s)
5:38:05 PM: Caching artifacts
5:38:05 PM: Started saving node modules
5:38:05 PM: Finished saving node modules
5:38:05 PM: Started saving build plugins
5:38:05 PM: Finished saving build plugins
5:38:05 PM: Started saving yarn cache
5:38:05 PM: Finished saving yarn cache
5:38:05 PM: Started saving pip cache
5:38:06 PM: Finished saving pip cache
5:38:06 PM: Started saving emacs cask dependencies
5:38:06 PM: Finished saving emacs cask dependencies
5:38:06 PM: Started saving maven dependencies
5:38:06 PM: Finished saving maven dependencies
5:38:06 PM: Started saving boot dependencies
5:38:06 PM: Finished saving boot dependencies
5:38:06 PM: Started saving rust rustup cache
5:38:06 PM: Finished saving rust rustup cache
5:38:06 PM: Started saving rust cargo bin cache
5:38:06 PM: Finished saving rust cargo bin cache
5:38:06 PM: Started saving go dependencies
5:38:06 PM: Finished saving go dependencies
5:38:08 PM: Build script success
5:38:08 PM: Starting to deploy site from ''
5:38:08 PM: Creating deploy tree
5:38:09 PM: Creating deploy upload records
5:38:09 PM: 5 new files to upload
5:38:09 PM: 3 new functions to upload
5:38:10 PM: Starting post processing
5:38:12 PM: Post processing - HTML
5:38:12 PM: Post processing - header rules
5:38:12 PM: Post processing - redirect rules
5:38:12 PM: Post processing done
5:38:13 PM: Site is live ✨
5:38:34 PM: Finished processing build request in 2m14.274321422s
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (2 by maintainers)
Commits related to this issue
- fix path https://github.com/netlify/next-runtime/issues/153#issuecomment-865230647 — committed to texttree/opencomponents.io by foxprogs 4 years ago
Hi @juanpprieto.
The path should be relative to the project root, so if the files live under
/public, I believe the config should be:And to read them you can try:
Let me know if this helps.
Game changer! 🔥🔥🔥
Thanks! @eduardoboucas
the platform solution is finally out!!! https://docs.netlify.com/configure-builds/file-based-configuration/#functions
please go ahead and give it a shot!
@MejanH hey! we pushed up a temporary solution for this supported in the plugin and wanted to let you know since you were the very first to surface this issue! i will note that this is a temporary, unstable solution. we’re also working on a greater, platform-wide solution for this type of file inclusion. if you’d like access to the short term next-specific plugin solution, feel free to email me lindsay@netlify.com or dm on twitter @levlinds. otherwise, i’ll leave this issue open until the longer term solution rolls out! ❤️
@juanpprieto hey there! my apologies for not circling back here!!! my teammate @eduardoboucas just recently shed some light on that question here. per his most recent comment, it’s something we’ll be rolling out soon. you can subscribe to #359 to see when eduardo gives that release update!
@coreyaus hey corey! per @eduardoboucas aka the engineer behind
included_files, this is something the team is working on (the process.cwd() stuff)!thanks so much for sharing your notes regardless, we appreciate it and i’m sure other users will too!!
i also left a comment on that community thread 👍
Thanks for the prompt response @lindsaylevine!
I’ve got this up and running now. Essentially I found that
process.cwd()didn’t work on Netlify (but did work in local development, and on Vercel. For more context, the previous version ofgetServerSidePropsI was using accessed the filesystem in a manner something like the below (I have inlined a helper function here for ease of reference):The revised version that does work across localhost, Netlify and Vercel borrows heavily from this repository: https://github.com/cassidoo/next-netlify-blog-starter and looks more like the below, where the
getPostsmethod is now pretty much identical to this: https://github.com/cassidoo/next-netlify-blog-starter/blob/master/utils/getPosts.jsFor that code to work you also need to run
yarn add raw-loaderand include this setting in yournext.config.js:It would be handy to have
process.cwd()set to the project root like it is in localhost and Vercel to avoid always having to include a hard-coded string reference like “…/…/posts” or “…/posts” or whatever, but not a big deal. Always open to ideas if people know of ways to make that reference more dynamic while staying on Netlify. At the momentprocess.cwd() === '/var/task'in the Netlify functions created for Server-Side Rendered (SSR) pagesAnyway, mostly just sharing in case these notes help anyone else (and also as a plug for all the excellent Netlify start repos that exist like the one linked in this comment!) 😄
PS: might also be worth posting the good news about the latest platform solution for this problem here too: https://answers.netlify.com/t/how-to-access-files-from-nextjs-api-function/35347/2
Thanks for the help. Will wait for this feature.
@MejanH ok WEW finally got this deployed and diagnosed! so here’s what’s going on:
because these pages are trying to use ISR (see
revalidateflag in yourgetStaticPropsfunctions), our plugin turns these pages into netlify functions. from within the function['s node env], the files (aka the markdown) you’re trying to read “from disk” are not bundled with those functions, so it’s failing to find them and erroring out.this is something we can/should address, but for now, if you want this to Just Work, don’t use ISR/revalidate. it will work as a plain SSG’d/prerendered page.
thanks for opening that separate repo for me and let me know if you have any other questions!! i’m going to change the title if that’s cool to be a little more specific to the issue 😃