blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Cannot import .gitignored files #323

Closed nickluger closed 3 years ago

nickluger commented 3 years ago

What is the problem?

I'm trying to import a JSON-file which is in our .gitignore using something like await import("i18n/en.json") in getStaticProps. (Or just import on the top, which doesn't work neither).

Context: We use this to import and provide an auto-generated locale file to be used by Rosetta for i18n. This file is auto generated on build or during development and shouldn't go into git, usually.

Paste all your error logs here:

Module not found: Can't resolve 'i18n/en.keys.json'
  42 |
  43 | export async function getStaticProps({ locale }: GetStaticPropsContext) {
> 44 |   console.log(await import("i18n/en.keys.json"));
     |                    ^
  45 |   return {
  46 |     props: { lngDict: {} },
  47 |   };
event - build page: /_error

Paste all relevant code snippets here:

export async function getStaticProps({ locale }: GetStaticPropsContext) {
 await import("i18n/en.keys.json");
// ...

What are detailed steps to reproduce this?

  1. Create a JSON-file somewhere, e.g. the public dir.
  2. Add it to your local .gitignore file.
  3. Import it in a Next.js page, statically or dynamically.
  4. Boom πŸ’₯

Workaround 1

  1. Remove the file from your .gitignore
  2. Hooray 🌈

Workaround 2

  1. If you happen to be in a monorepo like we are, add it to a .gitignore above your Blitz folder
  2. Hooray 🌈

Run blitz -v and paste the output here:

macOS Big Sur | darwin-x64 | Node: v14.17.5

blitz: 0.39.0 (local)

  Package manager: npm
  System:
    OS: macOS 11.5.2
    CPU: (8) x64 Apple M1
    Memory: 126.57 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.5 - /var/folders/0t/qf92ltfx37jblv7t_3_7v8mh0000gn/T/yarn--1629305144503-0.03753126972524701/node
    Yarn: 1.22.11 - /var/folders/0t/qf92ltfx37jblv7t_3_7v8mh0000gn/T/yarn--1629305144503-0.03753126972524701/yarn
    npm: 6.14.14 - /var/folders/0t/qf92ltfx37jblv7t_3_7v8mh0000gn/T/fnm_multishells/77055_1629103506935/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: Not Found
    blitz: Not Found
    prisma: Not Found
    react: Not Found
    react-dom: Not Found
    typescript: Not Found

Please include below any other applicable logs and screenshots that show your problem:

No response

flybayer commented 3 years ago

This will be fixed by a change coming soon (related to nextjs fork migration)

flybayer commented 3 years ago

Fixed in https://github.com/blitz-js/legacy-framework/issues/323