question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support config.includeFiles for @now/next

See original GitHub issue

There’s a message/thread in Spectrum about this.

Basically I can’t fs.readFileSync() inside an pages/api/whatever.ts because the files aren’t copied.

I’ve done some investigation in the code for the builders, and I don’t see any parity for the functionality that exists in @now/node. I imagine something should be added around here for that, and am happy to try a PR if you don’t think this is too crazy.

Here’s the info I posted in Spectrum:

I’m having this same issue with @now/next, so I have this in a now.json file:

{
  "version": 2,
  "builds": [
    {
      "src": "next.config.js",
      "use": "@now/next",
      "config": {
        "includeFiles": ["email-templates/**"]
      }
    }
  ]
}

Where a directory with this structure exists in the root of the app/directory:

email-templates
├── login
│   ├── html.pug
│   └── subject.pug
├── main.pug
└── mixins.pug

And I can’t read the files at all (I’ve tried all kinds of combinations to just find the files, and here’s the latest):

const templateFilePath = path.join(__dirname, 'email-templates', 'login', 'html.pug');
const templateContent = fs.readFileSync(templateFilePath).toString('utf8');

The error I get is:

Unhandled Promise Rejection    {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: ENOENT: no such file or directory, open '/email-templates/login/html.pug'","stack":["Runtime.UnhandledPromiseRejection: Error: ENOENT: no such file or directory, open '/email-templates/login/html.pug'","    at process.on (/var/runtime/index.js:37:15)","    at process.emit (events.js:203:15)","    at emitPromiseRejectionWarnings (internal/process/promises.js:119:20)","    at process._tickCallback (internal/process/next_tick.js:69:34)"],"reason":{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, open '/email-templates/login/html.pug'","code":"ENOENT","stack":["Error: ENOENT: no such file or directory, open '/email-templates/login/html.pug'","    at Object.openSync (fs.js:443:3)","    at Object.readFileSync (fs.js:343:35)","    at Object.sendLoginEmail (/var/task/.next/serverless/pages/api/v0/signup.js:564:71)","    at module.exports.L76w.__webpack_exports__.default (/var/task/.next/serverless/pages/api/v0/signup.js:471:67)","    at process._tickCallback (internal/process/next_tick.js:68:7)"],"errno":-2,"syscall":"open","path":"/email-templates/login/html.pug"},"promise":{}}
2019-09-26T14:35:19.168Z    bea5a417-7224-4397-b4ec-81b6838540a2    ERROR    Unhandled rejection: { Error: ENOENT: no such file or directory, open '/email-templates/login/html.pug'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at Object.sendLoginEmail (/var/task/.next/serverless/pages/api/v0/signup.js:564:71)
    at module.exports.L76w.__webpack_exports__.default (/var/task/.next/serverless/pages/api/v0/signup.js:471:67)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/email-templates/login/html.pug' }

And while the path looks weird (I’d expect __dirname to be /var/task, not /), it also doesn’t work if I try to read /var/task/email-templates/login/html.pug.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
BrunoBernardinocommented, Jul 6, 2020

Thanks! If I run into these issues again in the future I’ll add more info.

1reaction
gunarcommented, Jul 5, 2020

I just realized require('./file.json') works fine, so we just need to generate a json file at build time:

  1. Create a script that reads whatever files you need, and exports them as json
  2. Add this to package.json: "build": "node script.js>data.json && next build"
  3. Have your serverless function require the json as such require('../../data.json')

In my case it was even simpler. The output was static so I just wrote it directly into /public.

Hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

IncludeFile - OCLC Support
Learn how to use the IncludeFile config.txt directive to allow EZproxy to open a specified file and use it to configure EZproxy.
Read more >
next.config.js: Introduction
next.config.js is a regular Node.js module, not a JSON file. It gets used by the Next.js server and build phases, ...
Read more >
Configuration | Stylelint
Plugins are rules or sets of rules built by the community that support methodologies, toolsets, non-standard CSS features, or very specific use cases....
Read more >
Modify Apache Virtual Hosts with Include Files
Use the command line interface to add include files that modify the content of the virtual hosts in your Apache configuration.
Read more >
Cascading Configuration Files - Java Service Wrapper
0, it is possible to specify "include files" within a configuration file like cascading style. This is useful where there is a need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found