#Failed to preview after build on windows and arm64 deployment stuff
1 messages · Page 1 of 1 (latest)
> rfid_reader@0.0.1 preview E:\Website\RFID\server
> astro preview
error require is not defined in ES module scope, you can use import instead
File:
E:\Website\RFID\server\node_modules\@astrojs\node\dist\preview.js:13:23
Code:
12 | process.env.ASTRO_NODE_AUTOSTART = "disabled";
> 13 | const ssrModule = await import(serverEntrypoint.toString());
| ^
14 | if (typeof ssrModule.handler === "function") {
15 | ssrHandler = ssrModule.handler;
16 | } else {
Stacktrace:
ReferenceError: require is not defined in ES module scope, you can use import instead
at file:///E:/Website/RFID/server/dist/server/entry.mjs:7184:21
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Module.preview (file:///E:/Website/RFID/server/node_modules/@astrojs/node/dist/preview.js:13:23)
at async preview (file:///E:/Website/RFID/server/node_modules/astro/dist/core/preview/index.js:35:18)
at async runCommand (file:///E:/Website/RFID/server/node_modules/astro/dist/cli/index.js:158:22)
at async cli (file:///E:/Website/RFID/server/node_modules/astro/dist/cli/index.js:168:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rfid_reader@0.0.1 preview: `astro preview`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rfid_reader@0.0.1 preview script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\devst\AppData\Roaming\npm-cache\_logs\2022-12-23T18_52_41_027Z-debug.log
Referenced line: libs.set('process', require.resolve('process-es6')); (E:/Website/RFID/server/dist/server/entry.mjs:7184:21)
The log
does the build run on windows, or can you post an example project running on a VM and not running on ARM64 ? e.g. just repo or test with StackBlitz / Gitpod,...
That is upon running on windows
ah, ok, so your problem is the othe way around, you have a dependency that does not run on windows
May be issue because I use resolve in the astro config to fix fs
This is the problem:
ReferenceError: require is not defined in ES module scope, you can use import instead
so use import
ok, need an example repo project, otherwise not easy, can you reproduce it on a minimal example ?
with an example, I can give it a try, soon.
I have it on github
Currently privated, bacause I was lazy and used token in code...
But that doesn't matter I can regenerate it
I needed to use rolup plugin to use fs
May be the issue
But astro dev works perfectly
import { defineConfig } from 'astro/config';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// https://astro.build/config
import node from "@astrojs/node";
// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({ mode: "standalone" }),
vite: {
resolve: {
alias: {
fs: require.resolve('rollup-plugin-node-builtins'),
}
}
}
});
Config
Do you have type: "module" in your package.json?
Yeah… CJS/ESM interop is always a pain
Might be the require.resolve in the Astro config, but that code looks okay to me…
Yeah
That’s because it’s trying to bundle the rollup-plugin-node-builtins
The fs alias is in place because of fs not working with astro
It threw vite traced error
Hmm I have definitely used fs with the node adapter. Can you share the specific error?
Also what node version, just curious!
E:\Website\RFID\server>node --version
v14.18.1
E:\Website\RFID\server>npm --version
6.14.15
Huh. That’s very odd. We definitely externalize node built-ins by default.
Maybe try using node:fs as the import specifier?
Regardless, this is very annoying and you shouldn’t have to jump through hoops to use fs. I’d love to figure out what’s happening here and fix it.
Ok with node:fs it works
Bizarre, but I’m glad it works!
Gonna try to build it now
Now I can't build it! Great!
[commonjs--resolver] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
error Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
File:
E:\Website\RFID\server\node_modules\vite\dist\node\chunks\dep-5605cfa4.js:34107:11
Code:
34106 | function packageEntryFailure(id, details) {
34107 | throw new Error(
Failed to resolve entry for package "${id}".+
| ^
34108 |The package may have incorrect main/module/exports specified in its package.json+
34109 | (details ? ': ' + details : '.'));
34110 | }
Stacktrace:
Error: Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
at packageEntryFailure (file:///E:/Website/RFID/server/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:34107:11)
at resolvePackageEntry (file:///E:/Website/RFID/server/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:34104:5)
at tryNodeResolve (file:///E:/Website/RFID/server/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:33842:20)
at Object.resolveId (file:///E:/Website/RFID/server/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:33602:28)
at Object.handler (file:///E:/Website/RFID/server/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:45912:19)
at file:///E:/Website/RFID/server/node_modules/rollup/dist/es/shared/rollup.js:22748:40
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: astro build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\devst\AppData\Roaming\npm-cache_logs\2022-12-23T19_50_19_750Z-debug.log
This is extremely strange…
Confusing framework developers 🦾
If you run npm ls fs is there anything in the dependency tree that is actually a package named fs?
``--- [email protected]`
Why are you adding fs as dependency ? https://github.com/PanJohnny/RFIDSpotifyPlayerServer/blob/6cb05ae700a0720a79acad5d7011577af58c45d5/package.json#L17
Ah yes. fs is a node built in, not a regular NPM package
Right ✅️
If you remove that dependency and reinstall, then try to build, what do you get?
Also be sure to remove the node builtins polyfill.
Wdym?
Also the build works now
@types/node?
that was added by code
I removed the rollup
This is also weird, why is that ? https://github.com/PanJohnny/RFIDSpotifyPlayerServer/blob/6cb05ae700a0720a79acad5d7011577af58c45d5/astro.config.mjs#L16
That was because of that weird fs package
When I replace import fs with import node:fs it wasn't needed anymore
Ok time to push this build to my pi
Make sure you have same node version on pc and raspi, to avoid further issues.
That will be difficult
I need to use experimental node builds on raspi
Also, how can I change the port?
Is this correct?
export default defineConfig({
output: "server",
adapter: node({ mode: "standalone" }),
port: 80
});```
Ok found the version
Fingers crossed
you can use nvm, that's what I do, you can also try first and see, I have node 18 on both pc and raspi and Astro built dist folder is running fine.
Used wget
why also node 14, many packages are dropping support, best is 16, and 18 still edge but if you're adventerous, should be LTS.
why also unofficial, here official node website https://nodejs.org/en/download/
This matters
pi@raspberrypi:~ $ node -v
v14.18.1
Do I need to move only the dist contents?
Ik, I should update node on my pc. But this is just small silly project for my sister.
I don't need to optimize my code (I will regret this later)
sure, but using an up-to-date node version should make some pain points easier 👍
for your astro site? running npm run build should create everything needed for your site in dist/
no, that's the point, build does not work on ARM64
so fallback I managed is build on pc, copy to rasp, dist + dependencies, you can also run npm install on raspi, should work too
lol, be careful what you promise 😅
nice, idea
Is that still the case? Seems like what we figured out here was a different build issue.
That’s such a cool idea!
I may polish the code and make tutorial how to replicate the whole thing
yeah, name of post is confusing, that's what I clarified in the beginning when I got that even build on windows was failing, basically two issues
- build on ARM64 not supported
- build on windows project specific fails due to fs import issue
When I tried to build it on raspi it just outputed something like:
Platform arm64 not supported
Now I wait for npm i
yeah, litteraly, lol, I got a more implicit one, don't have one nearby, but I'll report it.
I think it was one of the deps
by the way, not even Next.js builds on raspi, for another reason, out of memory I think raspi suffocated.
I have the cheapest raspi 0
I use external wifi antena (with really slow internet connection) so npm install is nightmare
At least I am > 50% done
The website that I got the circuit for connecting RFID reader was DNS hijacked recently. The same day I was actually wiring it.
That was really great
Took me some time to rout to it using the ip
OK! Npm finished
No error yet 👀
It is building 👀
Looks like I won't be able to reproduce the issue maybe
Poor pi trying to handle node
would be even better, I would have to isolate my issue then, maybe node18,....
bad news, or good news, your build is failing, but I just tried my latest project version and it working !! building on ARM64 https://github.com/MicroWebStacks/astro-home-control @exotic shale sorry for wrong assumption, but again here since weeks, not any build woked, now I tried to report it and it first time ever works for me on raspi 4
looks like everything is working !!!
you need host to be true https://docs.astro.build/en/reference/configuration-reference/#serverhost