我正努力用Webpack(带有react + webpack + react-three-fiber的Gatsby项目)导入.gltf文件。
在开发模式下,出现此错误:
This relative module was not found:
⠀
* ../../static/gltf/bear_v2.gltf in ./src/components/CanvasWrapper.js
error ✖ 「wdm」:
ERROR in ./src/components/CanvasWrapper.js
Module not found: Error: Can't resolve '../../static/gltf/bear_v2.gltf' in '/Volumes/Data/DOCUMENTS/_htdocs/slenterende-beer/src/components'
@ ./src/components/CanvasWrapper.js 19:0-55 25:12-21 149:10-19
@ ./src/pages/index.js
@ ./.cache/sync-requires.js
@ ./.cache/app.js
@ multi ./node_modules/event-source-polyfill/src/eventsource.js (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false ./.cache/app
info ℹ 「wdm」: Failed to compile.
在开发期间,当我在import
和require
之间切换时,它突然起作用了。当我切换并重新启动项目时,它再次失败(直到切换)。我认为这是一个奇怪的缓存问题(?)。
我正在使用gltf-webpack-loader
加载文件。
现在,文件已放置在/static/gltf/model.gltf
中,但之前没有放置在/assets/
中,我想这是webpack所不喜欢的。
webpack规则: https://github.com/flowen/slenterendebeer/blob/master/gatsby-node.js
加载代码: https://github.com/flowen/slenterendebeer/blob/master/src/components/CanvasWrapper.js
进口位于第6行和第15行
这是构建错误(在netlify上):
10:02:42 PM: Error: ./static/gltf/bear.gltf
10:02:42 PM: Module not found: Error: Can't resolve './-0.707' in '/opt/build/repo/static/g ltf'
10:02:42 PM: resolve './-0.707' in '/opt/build/repo/static/gltf'
10:02:42 PM: using description file: /opt/build/repo/package.json (relative path: ./static/gltf)
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: using description file: /opt/build/repo/package.json (relative path: ./sta tic/gltf/-0.707)
10:02:42 PM: no extension
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: /opt/build/repo/static/gltf/-0.707 doesn't exist
10:02:42 PM: .mjs
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: /opt/build/repo/static/gltf/-0.707.mjs doesn't exist
10:02:42 PM: .js
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: /opt/build/repo/static/gltf/-0.707.js doesn't exist
10:02:42 PM: .jsx
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: /opt/build/repo/static/gltf/-0.707.jsx doesn't exist
10:02:42 PM: .wasm
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: /opt/build/repo/static/gltf/-0.707.wasm doesn't exist
10:02:42 PM: .json
10:02:42 PM: Field 'browser' doesn't contain a valid alias configuration
10:02:42 PM: /opt/build/repo/static/gltf/-0.707.json doesn't exist
10:02:42 PM: as directory
10:02:42 PM: /opt/build/repo/static/gltf/-0.707 doesn't exist
10:02:42 PM: [/opt/build/repo/static/gltf/-0.707]
10:02:42 PM: [/opt/build/repo/static/gltf/-0.707.mjs]
10:02:42 PM: [/opt/build/repo/static/gltf/-0.707.js]
10:02:42 PM: [/opt/build/repo/static/gltf/-0.707.jsx]
10:02:45 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
10:02:42 PM: [/opt/build/repo/static/gltf/-0.707.wasm]
10:02:42 PM: [/opt/build/repo/static/gltf/-0.707.json]
10:02:42 PM: @ ./static/gltf/bear.gltf ./-0.707