我使用npm安装了Material Table,该软件包具有@ date-io / date-fns作为软件包依赖项。
在构建中运行项目时,出现以下错误:
`ERROR in ./node_modules/material-table/dist/m-table-filter-row.js
Module not found: Error: Can't resolve '@date-io/date-fns' in 'project_folder\node_modules\material-table\dist'
@ ./node_modules/material-table/dist/m-table-filter-row.js 34:38-66
@ ./node_modules/material-table/dist/material-table.js
@ ./client/app/pages/details-page.js
@ ./client/app/app.js
@ ./client/app/index.js
`
`ERROR in ./node_modules/@date-io/date-fns/build/index.esm.js[watch:prod] Module not found: Error: Can't resolve 'date-fns/getHours' in 'project_folder\node_modules\@date-io\date-fns\build'`
在我看来,它是在根node_modules文件夹中搜索@ date-io。
当我从以下位置更改材料表包index.js中的import语句时,项目成功构建:
`import addDays from 'date-fns/addDays';`
至:
`import addDays from 'material_table/node_modules/date-fns/addDays';`