fab-spec / fab

πŸ’Ž FAB project specification & monorepo
https://fab.dev
MIT License
578 stars 37 forks source link

next12 #459

Open konsumer opened 2 years ago

konsumer commented 2 years ago

I'd like to help with getting fab working with nextjs 12.

Here is my initial test procedure, which basically comes from the fab & nextjs docs:

$ npx create-next-app@latest fab-next12
$ cd fab-next12

Creating a new Next.js app in /Users/konsumer/Desktop/fab-next12.

Using npm.

Installing dependencies:
- react
- react-dom
- next

added 14 packages, and audited 15 packages in 915ms

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Installing devDependencies:
- eslint
- eslint-config-next

added 208 packages, and audited 223 packages in 2s

68 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Initialized a git repository.

Success! Created fab-next12 at /Users/konsumer/Desktop/fab-next12
Inside that directory, you can run several commands:

  npm run dev
    Starts the development server.

  npm run build
    Builds the app for production.

  npm start
    Runs the built app in production mode.

We suggest that you begin by typing:

  cd fab-next12
  npm run dev

$ npx -y fab init                                                                              ξ‚² βœ”
   [Initializer] πŸ’Ž fab init β€” Auto-configure a repo for generating FABs πŸ’Ž
   [Initializer] Searching for a known project type…
                   If your project is not correctly detected,
                   or if the generated config is incorrect,
                   please leave some feedback at https://fab.dev/guides/known-project-types
   [Initializer] WARNING: NextJS on FABs only tested up until ^10.1.3. You have 12.1.6.
   [Initializer] If you have trouble, consider rolling back your local NextJS version.
   [Initializer] Success! Found a NextJS v9+ (dynamic) project. We know exactly how to configure this πŸ‘
   [Initializer] Ready to proceed. This process will:
                   β€’ Generate a fab.config.json5 file for your project
                   β€’ Add build:fab and related scripts to your package.json
                   β€’ Add .fab and fab.zip to your .gitignore
                   β€’ Install @fab/cli and related dependencies using npm

   [Initializer] Ok, proceeding…
   [Initializer] WARNING: Your NextJS project is not currently configured for a serverless build.
                   Currently your app is configured to build in server mode.
                   Update this in your next.config.js by setting target: 'serverless'
                   Continuing setup, but fab build will fail until this is changed.
   [Initializer] NOTE: Installing required FAB core dependencies:
                   β€’ @fab/cli
                   β€’ @fab/server
                   β€’ @fab/actions
   [Initializer] and the following project-specific plugins:
                   β€’ @fab/input-nextjs
                   β€’ @fab/plugin-render-html
                   β€’ @fab/plugin-rewire-assets
   [Initializer] using npm…

npm WARN deprecated @types/path-to-regexp@1.7.0: This is a stub types definition for path-to-regexp (https://github.com/pillarjs/path-to-regexp). path-to-regexp provides its own type definitions, so you don't need @types/path-to-regexp installed!
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated cli-ux@5.6.7: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

added 711 packages, and audited 934 packages in 16s

113 packages are looking for funding
  run `npm fund` for details

9 high severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
   [Initializer] Done!
   [Initializer] Now run npm run build:fab to build your project and generate a FAB from it!
                   or visit https://fab.dev/guides/getting-started for more info.
   [Initializer] πŸ’Ž All good πŸ’Ž

I test with npm run dev first, to make sure nextjs works. npm run build:fab:


> fab-next12@0.1.0 build:fab
> npm run build && npm run fab:build

> fab-next12@0.1.0 build
> next build

info  - Checking validity of types
info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
info  - Generating static pages (3/3)
info  - Finalizing page optimization

Page                                       Size     First Load JS
β”Œ β—‹ /                                      6.25 kB        81.2 kB
β”œ   β”” css/149b18973e5508c7.css             655 B
β”œ   /_app                                  0 B            74.9 kB
β”œ β—‹ /404                                   193 B          75.1 kB
β”” Ξ» /api/hello                             0 B            74.9 kB
+ First Load JS shared by all              74.9 kB
  β”œ chunks/framework-1f10003e17636e37.js   45 kB
  β”œ chunks/main-fc7d2f0e2098927e.js        28.7 kB
  β”œ chunks/pages/_app-69da446bea935969.js  493 B
  β”œ chunks/webpack-69bfa6990bb9e155.js     769 B
  β”” css/27d177a30947857b.css               194 B

Ξ»  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
β—‹  (Static)  automatically rendered as static HTML (uses no initial props)

> fab-next12@0.1.0 fab:build
> fab build

       [Builder] πŸ’Ž fab build πŸ’Ž
       [Builder] Reading plugins from config.
       [Builder] Found the following build-time plugins:
                   @fab/input-nextjs
                   @fab/plugin-render-html
                   @fab/plugin-rewire-assets
       [Builder] and the following runtime plugins:
                   node_modules/@fab/input-nextjs/runtime.js
                   node_modules/@fab/plugin-render-html/runtime.js
                   node_modules/@fab/plugin-rewire-assets/runtime.js
       [Builder] Proceeding with build phase.
       [Builder] Building @fab/input-nextjs:
Build failed!

Not serverless build
NextJS project needs to be set to target: serverless
You'll need to update your next.config.js file.
(https://fab.dev/guides/known-project-types#nextjs-9-dynamic-serverless)

    Error: Build failed!

I add target: 'serverless' to next.config.js, run npm run build:fab again:

> fab build

       [Builder] πŸ’Ž fab build πŸ’Ž
       [Builder] Reading plugins from config.
       [Builder] Found the following build-time plugins:
                   @fab/input-nextjs
                   @fab/plugin-render-html
                   @fab/plugin-rewire-assets
       [Builder] and the following runtime plugins:
                   node_modules/@fab/input-nextjs/runtime.js
                   node_modules/@fab/plugin-render-html/runtime.js
                   node_modules/@fab/plugin-rewire-assets/runtime.js
       [Builder] Proceeding with build phase.
       [Builder] Building @fab/input-nextjs:
[@fab/input-ne…] Reading files from /Users/konsumer/Desktop/fab-next12/.next
[…/input-nextjs] Finding all static HTML pages…
[…/input-nextjs] βœ” Found 3 static html pages.
[…/input-nextjs] Finding all dynamic NextJS entry points
    AssertionError: The expression evaluated to a falsy value:

      assert_1.default(ast.body.length === 1)

    Code: ERR_ASSERTION

What else is needed to make it work?

konsumer commented 2 years ago

Also, how do I get started deving on packages/input-nextjs, in general? I am used to pretty live feedback, automatic-building, etc, so I can test things while I'm working. Should I maybe start with unit-tests for things like getRenderCode?

Trying to start working on it, I get this with npx lerna bootstrap:

lerna notice cli v4.0.0
lerna info bootstrap root only
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 2 in 'fab-spec'
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 2 in 'fab-spec'

Trying to npm i && npm test in packages/input-nextjs, I need to install a bunch of undocumented dev-deps:

npm i -D chai tsconfig-paths nyc mocha @ts-tools/node 

Should I PR these dev-deps, or is there some other recommended way?

{
    "@ts-tools/node": "^4.0.0",
    "chai": "^4.3.6",
    "mocha": "^10.0.0",
    "nyc": "^15.1.0",
    "tsconfig-paths": "^4.0.0"
}