The "path" argument must be of type string. Received type undefined

eslint时,发生这种错误。

 ERROR  Error loading vue.config.js:
 ERROR  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.resolve (path.js:168:7)
    at getOutputPath (D:\nodejs\project\vue\vue-tip\vue.config.js:22:21)
    at Object.<anonymous> (D:\nodejs\project\vue\vue-tip\vue.config.js:38:16)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)

相关代码是这一行

path.resolve(__dirname, 'dist', process.env.VUE_APP_DIR, 'static')

搜了一大堆,,貌似很多人答不在点上,网上抄袭严重。。。。

想了下,应该是 认不出 process.env.VUE_APP_DIR,这个是运行时才有的,eslint可能查不出来,,

解决办法:

As of Node v6.0.0 undefined as an argument to various path methods won't do. It has to be an (empty) string (nodejs/node#5348).

Probably a loader you're using is erring on this (there are bug reports concerning this issue all over the place..) (Thus) solution: make sure that instead of undefined an empty string is passed.

加一个兜底空字符串,如下,即可。

path.resolve(__dirname, 'dist', process.env.VUE_APP_DIR || '', 'static')

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区