clh161 / react-router-sitemap-generator

15 stars 11 forks source link

Having problem with images when Im trying to generate sitemap #36

Open maitzeth opened 3 years ago

maitzeth commented 3 years ago
yarn run babel-node sitemap.js
yarn run v1.22.10
$ /Users/maitzeth/Documents/Work/project/node_modules/.bin/babel-node sitemap.js
/Users/maitzeth/Documents/Work/project/src/assets/images/video_preview.png:1
�PNG

SyntaxError: Invalid or unexpected token
    at wrapSafe (internal/modules/cjs/loader.js:984:16)
    at Module._compile (internal/modules/cjs/loader.js:1032:27)
    at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Object.newLoader [as .js] (/Users/maitzeth/Documents/Work/project/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/maitzeth/Documents/Work/project/src/components/SimpleUI/VideoPlayer.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)

Hello, im having this issue when IM strying to generate sitemap, only happens with images on the project.

benpryke commented 2 years ago

I hit this issue myself. Every component rendered by your Router will be imported indirectly when you import your routes file. Images, CSS and other files that require custom loaders will consequently fail to load in the node environment. Furthermore, components that cannot be rendered server-side will also fail, such as those with dependencies on window, navigator, document, etc.

I'm not sure what the right approach is here, but I assume it should not be required to import your entire application simply to parse the router.

xshuxin commented 1 year ago

I hit this issue myself. Every component rendered by your Router will be imported indirectly when you import your routes file. Images, CSS and other files that require custom loaders will consequently fail to load in the node environment. Furthermore, components that cannot be rendered server-side will also fail, such as those with dependencies on window, navigator, document, etc.

I'm not sure what the right approach is here, but I assume it should not be required to import your entire application simply to parse the router.

I have also encountered the same problem. Have you found a solution? Looking forward to receiving your reply~