#Failed to preview after build on windows and arm64 deployment stuff

1 messages · Page 1 of 1 (latest)

sand cliff
#

Hi, I am having a problem with running my windows build on my (windows) computer.

#
> 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

thorny breach
#

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,...

thorny breach
#

ah, ok, so your problem is the othe way around, you have a dependency that does not run on windows

sand cliff
#

May be issue because I use resolve in the astro config to fix fs

sand cliff
thorny breach
#

so use import

sand cliff
#

It is not in my code

#

It is in the generated one

#

in entry.mjs

thorny breach
#

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.

sand cliff
#

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

exotic shale
#

Do you have type: "module" in your package.json?

sand cliff
#

yes

#

I also tried to set it to commonjs

#

That was not the fix

exotic shale
#

Yeah… CJS/ESM interop is always a pain

#

Might be the require.resolve in the Astro config, but that code looks okay to me…

sand cliff
#

Yeah

sand cliff
#

That is code that astro build generates

exotic shale
#

That’s because it’s trying to bundle the rollup-plugin-node-builtins

sand cliff
#

The fs alias is in place because of fs not working with astro

#

It threw vite traced error

exotic shale
#

Hmm I have definitely used fs with the node adapter. Can you share the specific error?

#

Also what node version, just curious!

sand cliff
#
E:\Website\RFID\server>node --version
v14.18.1

E:\Website\RFID\server>npm --version
6.14.15
exotic shale
#

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.

sand cliff
#

Ok with node:fs it works

exotic shale
sand cliff
#

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

exotic shale
#

This is extremely strange…

sand cliff
#

Confusing framework developers 🦾

exotic shale
#

If you run npm ls fs is there anything in the dependency tree that is actually a package named fs?

sand cliff
thorny breach
sand cliff
#

Out of confusion ig

#

_<

exotic shale
#

Ah yes. fs is a node built in, not a regular NPM package

thorny breach
exotic shale
#

If you remove that dependency and reinstall, then try to build, what do you get?

#

Also be sure to remove the node builtins polyfill.

sand cliff
#

Also the build works now

#

@types/node?

#

that was added by code

#

I removed the rollup

sand cliff
#

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

thorny breach
#

Make sure you have same node version on pc and raspi, to avoid further issues.

sand cliff
#

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

thorny breach
# sand cliff That will be difficult

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.

sand cliff
#

Used wget

thorny breach
#

why also node 14, many packages are dropping support, best is 16, and 18 still edge but if you're adventerous, should be LTS.

sand cliff
#

This matters

pi@raspberrypi:~ $ node -v
v14.18.1
#

Do I need to move only the dist contents?

sand cliff
#

I don't need to optimize my code (I will regret this later)

stark tapir
#

sure, but using an up-to-date node version should make some pain points easier 👍

sand cliff
#

How is it with the build

#

Do I need to clone the whole repo or just move dist

stark tapir
#

for your astro site? running npm run build should create everything needed for your site in dist/

thorny breach
#

so fallback I managed is build on pc, copy to rasp, dist + dependencies, you can also run npm install on raspi, should work too

thorny breach
sand cliff
#

What I said was RFID card -> spotify song

#

That is all

thorny breach
#

nice, idea

exotic shale
exotic shale
sand cliff
#

I may polish the code and make tutorial how to replicate the whole thing

thorny breach
sand cliff
#

When I tried to build it on raspi it just outputed something like:

Platform arm64 not supported

#

Now I wait for npm i

thorny breach
#

yeah, litteraly, lol, I got a more implicit one, don't have one nearby, but I'll report it.

sand cliff
#

I think it was one of the deps

thorny breach
#

by the way, not even Next.js builds on raspi, for another reason, out of memory I think raspi suffocated.

sand cliff
#

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

thorny breach
#

would be even better, I would have to isolate my issue then, maybe node18,....

sand cliff
#

:sadtater:

#

Alright time for my build

#

😮

#

Opening port...

thorny breach
#

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

thorny breach
sand cliff
#

Yeah, I need to open 3000 now tho

#

To check if raspi can handle astro

thorny breach
sand cliff
#

Aaah

#

Time to rebuild

thorny breach
#
export default defineConfig({
  output: "server",
  server:{
    port:parseInt(process.env.SERVER_PORT),
    host:true
  },
  adapter: node({
    mode: 'standalone'
  })
});
#

or pass it as argument, otherwise you can't connect to raspi from outside of it.

sand cliff
#

Yeah

#

Waiting for the preview to launch

#

Then I'll see

#

I need to run it as super user

#

Let's f*cking go!

#

Christmas present saved

#

Few tweeks awaiting for me but I am so happy 🙂