我在运行npm start时收到无效的正则表达式错误

时间:2019-10-07 11:47:47

标签: react-native npm expo

我最近安装了这个博览会。我已经使用expo init创建了一个项目。 创建后,当我运行npm start时,我遇到了以下错误,请解决我的问题

> @ start C:\Users\ujwal\Desktop\Java\my-new-project
> expo start

Starting project at C:\Users\ujwal\Desktop\Java\my-new-project
Expo DevTools is running at http://localhost:19002
Opening DevTools in the browser... (press shift-d to disable)
error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class. Run CLI with --verbose flag for more details.

Metro Bundler process exited with code 1
Set EXPO_DEBUG=true in your env to view the stack trace.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `expo start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ujwal\AppData\Roaming\npm-cache\_logs\2019-10-07T11_19_27_567Z-debug.log

4 个答案:

答案 0 :(得分:11)

您必须对此文件{project_root}\node_modules\metro-config\src\defaults\blacklist.js

进行更改

存在无效的正则表达式,需要更改。我将sharedBlacklist下的第一个表达式更改为:

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

希望对您有帮助。...

答案 1 :(得分:1)

似乎您遇到此错误:https://github.com/facebook/react-native/issues/26598。根据问题单,您有一些选择:

第一个选择:降级到节点10.16.3 LTS

第二个选项:如果您使用Yarn,请在package.json中添加一个“ resolutions”属性,以指向已解决问题的Metro-config版本:

  "resolutions": {
    "metro-config": "0.57.0"
  },

第三种选择:如果使用npm而不是yarn,则需要找到一种方法来将“ metro-config”子依赖关系固定为“ 0.57.0”。我不知道该怎么做,也许npm-shrinkwrap可以为您提供帮助。

答案 2 :(得分:0)

在Windows上使用react(而不是react-native)会遇到相同的问题。使用更新版本的node对其进行了修复。

答案 3 :(得分:0)

在安装新的expo-template-tabs项目然后运行expo start之后,今天我遇到了同样的问题。

您将需要在文件中进行更改:

{project_root}\node_modules\metro-config\src\defaults\blacklist.js

有一个无效的正则表达式,需要更改。因此,请更改此内容:

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

由Kishan Gujarati提供的this answer上可见。