Unable to import Fastify
robtweed opened this issue · 4 comments
I see a max string error occurring if I try to import Fastify:
await emulator.fs.init({
'package.json': JSON.stringify({
name: 'my-app',
dependencies: {
fastify: "latest"
}
}),
'index.js': `
import Fastify from 'fastify';
...etc
Importing Express works OK. I assume the Fastify module is simply too big for the way Nodebox handles things?
Can you create a complete reproducible we can run?
Edit: @danilowoz created an example for this internally, will look into it and probably fix it today (depending on how deep this goes)
For completeness, here's my self-contained demo:
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Nodebox test</title>
</head>
<body>
<script type="module" src="/js/errordemo.js"></script>
<iframe id="preview"></iframe>
</body>
</html>
/js/errordemo.js:
(async () => {
const {Nodebox} = await import('https://unpkg.com/@codesandbox/nodebox@0.1.0/build/index.mjs');
const emulator = new Nodebox({
iframe: document.getElementById('preview'),
});
await emulator.connect();
await emulator.fs.init({
'package.json': JSON.stringify({
name: 'my-app',
dependencies: {
fastify: "latest"
}
}),
'index.js': `
import Fastify from 'fastify';
console.log(1111111);
`
});
const shell = emulator.shell.create();
const {id} = await shell.runCommand('node', ['index.js']);
//const { url } = await emulator.preview.getByShellId(id);
console.log(id);
})();
The crash occurs on the Fastify import line, so the console.log() after it never shows up.
There's no urgency - I should be doing other work anyway but I have to admit this stuff is way too fascinating! :-)
BTW in case anyone is wondering about the (async () => { ... })(); wrapper around the main module: whilst unnecessary for Chrome and Firefox, Safari needs it in order to run async/await modules.
Implemented the missing api's for this today, resulting in a pretty much spec compliant http#server, dns#lookup and buffer#constants.
Our internal tests regarding fastify seem to be working, let me know if this is still broken, otherwise feel free to close the issue.
Thanks again for testing and reporting these issues, fastify was a great addition to our test suite
Yes, Fastify is working a treat for me now - awesome stuff!