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 on Windows: TypeError: Cannot read properties of null (reading 'replace') #107

Open
2 tasks done
cet351 opened this issue Mar 26, 2023 · 0 comments
Open
2 tasks done

Comments

@cet351
Copy link

cet351 commented Mar 26, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.13.0

Plugin version

4.0.0

Node.js version

18.15.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

21H2

Description

Started to use this plugin, created a simple server + client app following the README.

	await server.register(FastifyVite, {
		root: import.meta.url,
		dev: dev || process.argv.includes('--dev'),
		// clientModule: 'index.js',
		async createRenderFunction ({ createApp }) {
			return async () => ({
				element: await renderToString(createApp())
			});
		}
	});

Without the clientModule configuration (which works on Linux), I get this error:

TypeError: Cannot read properties of null (reading 'replace')
    at loadClient (D:\my\project\node_modules\@fastify\vite\mode\development.js:28:70)
    at Vite.setup (D:\my\project\node_modules\@fastify\vite\mode\development.js:51:30)
    at async Vite.ready (D:\my\project\node_modules\@fastify\vite\index.js:32:55)
    at async main (file:///D:/my/project/server.js:28:2)

With that, I get a different error:

(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.
Error: ENOENT: no such file or directory, mkdir 'D:/D:/my/project/client/.vite/deps_temp_d4cc20c3'
    at Object.mkdirSync (node:fs:1396:3)
    at runOptimizeDeps (file:///D:/my/project/node_modules/vite/dist/node/chunks/dep-79892de8.js:44657:14)
    at Timeout._onTimeout (file:///D:/my/project/node_modules/vite/dist/node/chunks/dep-79892de8.js:44060:46)
Waiting for the debugger to disconnect...
file:///D:/my/project/node_modules/vite/dist/node/chunks/dep-79892de8.js:41096
        const err = new Error(`Failed to load url ${url} (resolved id: ${id})${importer ? ` in ${importer}` : ''}. ${msg}`);
                    ^

Error: Failed to load url D:\D:\my\project\client\index.js (resolved id: D:\D:\my\project\client\index.js). Does the file exist?      
    at loadAndTransform (file:///D:/my/project/node_modules/vite/dist/node/chunks/dep-79892de8.js:41096:21) {
  code: 'ERR_LOAD_URL'
}

Notice the double D:\D:\ in the file names in the error message.

Steps to Reproduce

  1. Create a simple project on Windows following instructions in README;
  2. Run npm run dev.

This is actually my server.js The site-info.mjs module is just a simple object:

import Fastify from 'fastify';
import FastifyVite from '@fastify/vite';
import sensible from '@fastify/sensible';
import { renderToString } from 'vue/server-renderer';

import site_info from './svr/site-info.mjs';

export async function main (dev) {
	const server = Fastify();

	await server.register(sensible);
	await server.register(FastifyVite, {
		root: import.meta.url,
		dev: dev || process.argv.includes('--dev'),
		clientModule: 'index.js',
		async createRenderFunction ({ createApp }) {
			return async () => ({
				element: await renderToString(createApp())
			});
		}
	});

	server.setErrorHandler((err, req, reply) => {
		console.error(err);
		reply.send(err);
	});

	await server.vite.ready();

	server.get('/', async (req, reply) => {
		reply.html(await reply.render());
	});
	server.get('/about', (req, reply) => { reply.send(site_info); });

	return server;
}

main().then(server => {
	server.listen({ port: 3000 });
	console.log('Server listening on port 3000');
});

Expected Behavior

Just as how it works on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant