引用 SharePoint 框架 Web 部件中的图像



我正在尝试创建一个包含图像的简单SharePoint Online WebPart。 问题是未显示打包在 WebPart 中的图像。

我找到了这个解决方案: https://mattjimison.com/2017/06/03/referencing-images-sharepoint-framework-webpart/

但问题是我在执行gulp serve时出现错误:

[10:19:10] Finished subtask 'post-copy' after 4.25 ms
[10:19:10] Starting subtask 'collectLocalizedResources'...
Request: '/node_modules/@microsoft/sp-page-context/dist/sp-page-context.js'
[10:19:10] Finished subtask 'collectLocalizedResources' after 26 ms
[10:19:10] Starting subtask 'configure-webpack'...
[10:19:11] Finished subtask 'configure-webpack' after 561 ms
[10:19:11] Starting subtask 'webpack'...
Request: '/node_modules/@microsoft/sp-component-base/dist/sp-component-base.js'
Request: '/node_modules/@microsoft/sp-extension-base/dist/sp-extension-base_en-us.js'
Request: '/node_modules/@microsoft/sp-application-base/dist/sp-application-base_en-us.js'
Request: '/node_modules/react/dist/react.js'
Request: '/node_modules/react-dom/dist/react-dom.js'
[10:19:11] Error - [webpack] 'dist':
./lib/webparts/socialLinks/SocialLinksWebPart.js
Module not found: Error: Can't resolve 'set-webpack-public-path' in 'c:runemygitspfx-social-linkslibwebpartssocialLinks'
resolve 'set-webpack-public-path' in 'c:runemygitspfx-social-linkslibwebpartssocialLinks'
Parsed request is a module
using description file: c:runemygitspfx-social-linkspackage.json (relative path: ./lib/webparts/socialLinks)
after using description file: c:runemygitspfx-social-linkspackage.json (relative path: ./lib/webparts/socialLinks)
resolve as module
c:runemygitspfx-social-linkslibwebpartssocialLinksnode_modules doesn't exist or is not a directory
c:runemygitspfx-social-linkslibwebpartsnode_modules doesn't exist or is not a directory
c:runemygitspfx-social-linkslibnode_modules doesn't exist or is not a directory
c:runemygitnode_modules doesn't exist or is not a directory
c:runemynode_modules doesn't exist or is not a directory
looking for modules in c:runemygitspfx-social-linksnode_modules
using description file: c:runemygitspfx-social-linkspackage.json (relative path: ./node_modules)

好像是缺少模块?如何启动并运行它?

案例已结案

案例通过以下方式解决:

npm install @microsoft/loader-set-webpack-public-path
npm install @microsoft/set-webpack-public-path-plugin --save-dev

并用require("@microsoft/loader-set-webpack-public-path!");替换require('set-webpack-public-path!')

-符文

最新更新