首页 > 解决方案 > 收到以下错误无法读取未定义的属性“startsWith”

问题描述

在 laravel 8 上安装带有惯性 js 的反应后。运行“npm run dev”时出现以下错误

PS D:\Projects\Inertiajs with react and laravel\project> npm run dev

> @ dev D:\Projects\Inertiajs with react and laravel\project
> npm run development


> @ development D:\Projects\Inertiajs with react and laravel\project
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js

98% after emitting SizeLimitsPlugin

 ERROR  Failed to compile with 4 errors                                                                                                             6:35:46 PM

TypeError: Cannot read property 'startsWith' of undefined
    at isRelative (D:\Projects\Inertiajs with react and laravel\project\node_modules\friendly-errors-webpack-plugin\src\formatters\moduleNotFound.js:5:17)

标签: reactjslaravel

解决方案


我在尝试在 laravel 8 上安装惯性/反应时遇到了同样的问题。我通过将 Pages 文件夹添加到 laravel 项目中的资源/js 来修复错误。发生这种情况是因为遵循惯性文档,您参考

resolveComponent={name => require( ./Pages/${name}).default}

在 app.js 渲染函数中,但该文件夹在您创建它之前不存在。祝你好运!


推荐阅读