Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined #4586

Closed
hqm19 opened this issue May 5, 2020 · 0 comments · Fixed by #4499
Labels
type(ssr) UmiJS SSR

Comments

@hqm19
Copy link

hqm19 commented May 5, 2020

What happens?

Use umi-server with ssr config "disableExternal: true" got a runtime error:

➜  normal git:(master) ✗ node server.js
internal/validators.js:125
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:125:11)
    at Object.dirname (path.js:1260:5)
    at resolve (/.../umi-server/examples/normal/dist/umi.server.js:1273:22)
    at module.exports../node_modules/_app-root-path@2.2.1@app-root-path/lib/app-root-path.js.module.exports (/.../umi-server/examples/normal/dist/umi.server.js:1156:20)
    at Object.<anonymous> (/.../umi-server/examples/normal/dist/umi.server.js:1119:18)
    at Object../node_modules/_app-root-path@2.2.1@app-root-path/index.js (/.../umi-server/examples/normal/dist/umi.server.js:1120:30)
    at __webpack_require__ (/.../umi-server/examples/normal/dist/umi.server.js:687:30)
    at fn (/.../umi-server/examples/normal/dist/umi.server.js:61:20)
    at createLocalStorage (/.../umi-server/examples/normal/dist/umi.server.js:22395:23)
    at Object../src/pages/index.tsx (/.../umi-server/examples/normal/dist/umi.server.js:63967:67)

Mini Showcase Repository(REQUIRED)

Just the official umi-server examples:
https://github.com/umijs/umi-server/tree/master/examples/normal

How To Reproduce

  1. git clone https://github.com/umijs/umi-server.git && cd examples/normal && cnpm i
  2. modify .umirc.ts, change ssr config to
  //ssr: true,
  ssr: {
    disableExternal: true,
  },
  1. cnpm install localstorage-ponyfill -S
  2. modify src/pages/index.tsx as below
import React from 'react';
import styles from './index.css';
import { createLocalStorage } from "localstorage-ponyfill"

export const localStorage = createLocalStorage()
export default function() {
  localStorage.setItem("key1", "v1")
  let v1 = localStorage.getItem("key1")
  console.log("v1:"+v1)
  return (
    ...
  );
}
  1. umi dev
  2. after umi dev ready, ctrl-c to break it. get dist generated as below
➜  normal git:(master) ✗ ll dist
total 9816
drwxr-xr-x   9  staff      288  5  5 10:45 .
-rw-r--r--   1  staff  2309225  5  5 10:45 umi.server.js.map
-rw-r--r--   1  staff  2413680  5  5 10:45 umi.server.js
-rw-r--r--   1  staff      172  5  5 10:45 ssr-client-mainifest.json
-rw-r--r--   1  staff      324  5  5 10:08 index.html
-rw-r--r--   1  staff   283820  5  5 10:08 umi.js
-rw-r--r--   1  staff      549  5  5 10:08 umi.css
drwxr-xr-x   3  staff       96  5  5 10:08 static
drwxr-xr-x  22  staff      704  5  5 10:08 ..

if use 'umi build' here directly, the config "disableExternal: true" sames doesn't work, and umi.server.js doesn't contains the dependencies.

  1. node server.js
internal/validators.js:125
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:125:11)
    at Object.dirname (path.js:1260:5)
    at resolve (/.../umi-server/examples/normal/dist/umi.server.js:1273:22)
    ...

Context

  • Umi Version:
    2.13.13
  • Node Version:
    v10.16.3
  • Platform:
    Darwin Kernel Version 19.3.0
    macOS 10.15.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type(ssr) UmiJS SSR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants