首页 > 解决方案 > gatsby develop 显示错误“TypeError:预期模式为非空字符串”

问题描述

当我运行gatsby develop错误发生

D:\[Web dev]\gatsby-test\my-gatsby-project>gatsby develop
info Cache exists but contains no nodes. There should be at least some nodes available so it seems the cache was corrupted. Disregarding the cache and proceeding as if there was none.
success open and validate gatsby-configs, load plugins - 0.600s
success onPreInit - 0.025s
success initialize cache - 0.016s
⠋ copy gatsby files
C:\Users\sayee\AppData\Roaming\npm\node_modules\gatsby-cli\node_modules\yoga-layout-prebuilt\yoga-layout\build\Release\nbind.js:53
        throw ex;
        ^

TypeError: Expected pattern to be a non-empty string
    at picomatch (D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\picomatch\lib\picomatch.js:48:11)
    at createPattern (D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\anymatch\index.js:27:18)
    at D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\anymatch\index.js:91:21
    at Array.map (<anonymous>)
    at anymatch (D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\anymatch\index.js:91:6)
    at D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\chokidar\index.js:272:51
    at Array.every (<anonymous>)
    at D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\chokidar\index.js:270:22
    at Array.some (<anonymous>)
    at WatchHelper.filterDir (D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\chokidar\index.js:269:43)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\chokidar\index.js:647:10)
    at ReaddirpStream.NodeFsHandler._boundHandleError (D:\[Web dev]\gatsby-test\my-gatsby-project\node_modules\chokidar\lib\nodefs-handler.js:303:43)
    at ReaddirpStream.emit (events.js:375:28)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)

但是gatsby build两者gatsby serve都可以正常工作。

我什至还没有开始在其中添加任何新文件或代码。我只是使用了 gatsby 启动器(我也尝试使用不同的启动器)

gatsby new my-hello-world-starter https://github.com/gatsbyjs/gatsby-starter-hello-world

我还创建了 gatsbynpm init gatsby仍然有同样的错误

这是 package.json 文件

{
  "name": "gatsby-starter-hello-world",
  "private": true,
  "description": "A simplified bare-bones starter for Gatsby",
  "version": "0.1.0",
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "dependencies": {
    "gatsby": "^3.10.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  },
  "devDependencies": {
    "prettier": "2.3.2"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

我在用

node:14.17.1
npm:6.14.14 (i also tried npm:7.1x.x)
gatsby-cli:3.10.2

我尝试了几次删除缓存,删除 node_modules 和 package-lock.json 文件并重新安装依赖项npm install

标签: npmgatsbynode-modules

解决方案


推荐阅读