Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error demo #523

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/fastify-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"path-to-regexp": "^6.2.1",
"sanitize-filename": "^1.6.3",
"stream-template": "^0.0.10",
"vite": "^2.9.15",
"vite": "^5.0.0",
"wouter": "^2.7.5"
},
"peerDependencies": {
Expand Down Expand Up @@ -104,4 +104,4 @@
"README.md",
"LICENSE"
]
}
}
2 changes: 1 addition & 1 deletion packages/fastify-renderer/src/node/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class FastifyRendererPlugin {
this.devMode = incomingOptions.devMode ?? process.env.NODE_ENV != 'production'

this.vite = incomingOptions.vite || {}
this.vite.base ??= '/.vite/'
this.vite.base ??= '/.vite/.vite/'
this.viteBase = this.vite.base
this.assetsHost = incomingOptions.assetsHost || ''
this.hooks = incomingOptions.hooks || []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ export class ReactRenderer implements Renderer {
return await this.devServer!.ssrLoadModule(id)
} else {
const builtPath = path.join(this.plugin.serverOutDir, mapFilepathToEntrypointName(id))
return require(builtPath)
// Error: require() of ES Module /Users/slava.knyazev/fastify-renderer/packages/test-apps/simple-react/dist/server/~ImperativeApple.tsx.mjs not supported.
return import(builtPath) //This throws an error
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-renderer/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const cwd = process.cwd()
export const mapFilepathToEntrypointName = (filepath: string, base = '') => {
const prefix = longestCommonPrefix(cwd, filepath)
filepath = filepath.slice(prefix.length)
return base.replace(/\//g, '~') + filepath.replace(/\//g, '~')
return base.replace(/\//g, '~') + filepath.replace(/\//g, '~') + '.mjs'
}

export const escapeRegex = (string: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/test-apps/simple-react/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const server = async () => {
include: ['react', 'react-dom', 'react-dom/server', 'wouter', 'path-to-regexp'],
},
},
devMode: false,
})

const ImperativeApple = server.registerRenderable(require.resolve('./ImperativeApple'))
Expand Down
Loading