Error: the URL must be of a scheme file
ohmree opened this issue · 3 comments
ohmree commented
When I run my file with esmo
or node --loader=esbuild-node-loader
I get the following error:
$ pnpx esmo src/index.ts
(node:1316088) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
at new NodeError (node:internal/errors:371:5)
at fileURLToPath (node:internal/url:1372:11)
at resolve (file:///home/ohmree/code/js/contest_buddy/node_modules/.pnpm/esbuild-node-loader@0.1.1/node_modules/esbuild-node-loader/loader.mjs:20:16)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_INVALID_URL_SCHEME'
}
Where the contents of index.ts
are as follows:
import fs from 'node:fs';
import path from 'node:path';
import {App} from '@tinyhttp/app';
import {logger} from '@tinyhttp/logger';
import {json} from 'milliparsec';
import {PrismaClient} from '@prisma/client';
import clientViteConfig from 'client/vite.config';
import {createServer as createViteServer} from 'vite';
import sirv from 'sirv';
const prisma = new PrismaClient();
const app = new App();
const api = new App();
const isProd = process.env['NODE_ENV'] === 'production';
(async () => {
api
.use(json())
.get('/users', async (_request, response) => {
response
.status(200)
.json(await prisma.user.findMany())
.end();
})
.get('/users/:id', async (request, response) => {
const user = await prisma.user.findUnique({
where: {id: request.params['id']}
});
if (user) {
response.status(200).json(user).end();
} else {
response.status(404).json({message: 'User not found'}).end();
}
});
app.use(logger()).use('/api', api);
if (isProd) {
app.use(sirv(path.resolve(__dirname, '../client')));
} else {
const viteServer = await createViteServer({
server: {
middlewareMode: 'ssr',
cors: true,
hmr: true
},
...clientViteConfig
});
console.log(viteServer.config.server);
app.use(viteServer.middlewares);
app.use('*', async (request, response) => {
const url = request.originalUrl;
try {
const template = fs.readFileSync(
path.resolve(__dirname, '../../client/index.html'),
'utf-8'
);
const appHtml = await viteServer.transformIndexHtml(url, template);
response.status(200).set({'Content-Type': 'text/html'}).end(appHtml);
} catch (_error: unknown) {
const error = _error as Error;
viteServer.ssrFixStacktrace(error);
console.error(error);
response.status(500).end(error.message);
}
});
}
app.listen(3000);
})();
Is this a bug in esbuild-node-loader?
ohmree commented
I'm still getting an error :/
$ pnpm i -D github:antfu/esbuild-node-loader
../.. | +2 +
../.. | Progress: resolved 244, reused 244, downloaded 0, added 0, done
../../node_modules/.pnpm/esbuild@0.12.17/node_modules/esbuild: Running postinstall script, done in 90ms
devDependencies:
+ esbuild-node-loader 0.2.0
$ node --loader=esbuild-node-loader --experimental-specifier-resolution=node src/index.ts
(node:2075653) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
at new NodeError (node:internal/errors:371:5)
at fileURLToPath (node:internal/url:1372:11)
at resolve (file:///home/ohmree/code/js/contest_buddy/node_modules/.pnpm/github.com+antfu+esbuild-node-loader@a798b862f25b5b5a1798aec56ceec0e6689e24be/node_modules/esbuild-node-loader/loader.mjs:24:18)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_INVALID_URL_SCHEME'
}
nettybun commented
Can you open /home/ohmree/code/js/contest_buddy/node_modules/.pnpm/github.com+antfu+esbuild-node-loader@a798b862f25b5b5a1798aec56ceec0e6689e24be/node_modules/esbuild-node-loader/loader.mjs
and put a console.log('resolve specifier', specifier);
on the first line of the resolve()
function? Then it will tell you the problematic URL when you re-run