solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

`solid-start-static` adapter throws ERR_INVALID_ARG_TYPE(

Open LiQuidProQuo opened this issue 3 years ago • 2 comments

repro steps

1. pnpm create solid
1.1 selected options: template:bare ssr:yes  typescript:yes

3. pnpm add -d solid-start-static

4. pnpm build

build log

solid-start build 
 version  0.1.0
 adapter  static

solid-start building client...
vite v3.1.3 building for production...
✓ 56 modules transformed.
dist/public/manifest.json                      0.93 KiB
dist/public/ssr-manifest.json                  2.39 KiB
dist/public/assets/_...404_.00985c49.js        0.56 KiB / gzip: 0.37 KiB
dist/public/assets/index.76b9a9c1.js           0.75 KiB / gzip: 0.44 KiB
dist/public/assets/entry-client.d870915a.css   0.37 KiB / gzip: 0.26 KiB
dist/public/assets/index.fdb6b3cf.css          0.30 KiB / gzip: 0.21 KiB
dist/public/assets/entry-client.d40d4aa7.js    32.01 KiB / gzip: 12.13 KiB
solid-start client built in: 1.704s

solid-start building server...
vite v3.1.3 building SSR bundle for production...
✓ 56 modules transformed.
.solid/server/manifest.json     0.18 KiB
.solid/server/entry-server.js   49.89 KiB
solid-start server built in: 688.97ms

/workspaces/start4/src/routes
node:internal/errors:856
  const err = new Error(message);
              ^

Error: Command failed: node /workspaces/start4/node_modules/.pnpm/[email protected]/node_modules/solid-ssr/static/writeToDisk.mjs /workspaces/start4/.solid/server/server.js /workspaces/start4/dist/public/*404.html /*404 --trace-warnings
node:internal/fs/utils:887
  throw new ERR_INVALID_ARG_TYPE(
  ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at writeFile (node:fs:2160:5)
    at file:///workspaces/start4/node_modules/.pnpm/[email protected]/node_modules/solid-ssr/static/writeToDisk.mjs:8:5
    at FSReqCallback.oncomplete (node:fs:196:23) {
  code: 'ERR_INVALID_ARG_TYPE'
}

    at ChildProcess.exithandler (node:child_process:400:12)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1093:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5) {
  code: 1,
  killed: false,
  signal: null,
  cmd: 'node /workspaces/start4/node_modules/.pnpm/[email protected]/node_modules/solid-ssr/static/writeToDisk.mjs /workspaces/start4/.solid/server/server.js /workspaces/start4/dist/public/*404.html /*404 --trace-warnings',
  stdout: '',
  stderr: 'node:internal/fs/utils:887\n' +
    '  throw new ERR_INVALID_ARG_TYPE(\n' +
    '  ^\n' +
    '\n' +
    'TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined\n' +
    '    at writeFile (node:fs:2160:5)\n' +
    '    at file:///workspaces/start4/node_modules/.pnpm/[email protected]/node_modules/solid-ssr/static/writeToDisk.mjs:8:5\n' +
    '    at FSReqCallback.oncomplete (node:fs:196:23) {\n' +
    "  code: 'ERR_INVALID_ARG_TYPE'\n" +
    '}\n'
}

package.json

{
  "name": "start4",
  "scripts": {
    "dev": "solid-start dev",
    "build": "solid-start build",
    "start": "solid-start start"
  },
  "type": "module",
  "devDependencies": {
    "solid-start-node": "^0.1.0",
    "typescript": "^4.8.3",
    "vite": "^3.1.0"
  },
  "dependencies": {
    "@solidjs/meta": "^0.28.0",
    "@solidjs/router": "^0.4.3",
    "solid-js": "^1.5.4",
    "solid-start": "^0.1.0",
    "solid-start-static": "^0.1.0",
    "undici": "^5.10.0"
  },
  "engines": {
    "node": ">=14"
  }
}

LiQuidProQuo avatar Sep 25 '22 19:09 LiQuidProQuo

I found I can get a working build by doing the following steps:

  1. npm create solid@next
  2. Initialized as bare, ssr=false, ts=true
  3. npm i
  4. npm i --save-dev solid-start-static
  5. Open vite.config.ts, add adapter: "solid-start-static" and remove ssr: false (ssr: false must be removed)
  6. Comment out // import { HttpStatusCode } from "solid-start/server"; and {/* <HttpStatusCode code={404} /> */} from [...404].tsx

Then and only then can I build

{
  "name": "demo-solid-start-4",
  "scripts": {
    "dev": "solid-start dev",
    "build": "solid-start build",
    "start": "solid-start start"
  },
  "type": "module",
  "devDependencies": {
    "solid-start-node": "^0.1.0",
    "solid-start-static": "^0.1.0",
    "typescript": "^4.8.3",
    "vite": "^3.1.0"
  },
  "dependencies": {
    "@solidjs/meta": "^0.28.0",
    "@solidjs/router": "^0.4.3",
    "solid-js": "^1.5.4",
    "solid-start": "^0.1.0",
    "undici": "^5.10.0"
  },
  "engines": {
    "node": ">=14"
  }
}

zaydek avatar Sep 25 '22 19:09 zaydek

static entry generation, does not explicitly handles the 404 status code case ( see entry.js#L26 ) as a result the request returns undefined, which then fails as a valid data input in writeToDisk.js write call.

if 404 is explicitly handled in entry.js, and the content is returned, the static file generation is *successful, with the exception that there are oddly two files 404.html and *404.html (is that expected?)

image

https://github.com/solidjs/solid-start/blob/main/packages/start-static/entry.js#L26-L28

- if (webRes.status === 200) {
+ if (webRes.status === 200 || webRes.status === 404) {

alternatively return response body for any status code(to cover more cases) except for the redirect handling.

LiQuidProQuo avatar Sep 25 '22 20:09 LiQuidProQuo

Can't reproduce: https://stackblitz.com/edit/github-ov6sy6

Possibly already fixed?

ryansolid avatar Dec 30 '22 08:12 ryansolid