我正在尝试在Sapper应用程序中打开并读取.md文件的目录。我尝试了导入,但是它不允许使用字符串表达式(`file $ {index} .md`)。因此,我尝试通过fs节点模块打开和读取文件,但在服务器中收到以下消息:
preferring built-in module 'fs' over local alternative at 'fs', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
preferring built-in module 'fs' over local alternative at 'fs', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
'fs' is imported by src/routes/blog/[slug].svelte, but could not be resolved – treating it as an external dependency
'default' is imported from external module 'fs' but never used
如果要访问文件系统,则应在服务器路由中进行操作,即-.js文件,例如routes/blog/[slug].json.js
(将与/blog/:slug.json
对应),而不是在页面中,将同时在服务器和客户端上运行。