Astro部署到CloudFlare Pages和Netlify可能会遇到的问题
持续更新中...
一 .env环境变量无法读取
在Astro中使用directus JavaScript sdk调用数据无法部署到cloudflare Pages,netlify同样尝试失败,如果改为“await fetch”一切正常,原因是该项目使用了.env文件,而再Pages和netlify中均无法读取该数据,解决该问题以CF Pages为例需要使用Environment variables,把相应的变量添加进去即可。

这是出错的log
11:49:35 PM: build-image version: 340a5296c836ef3d99ac1d871c6447bb7a417c33 (focal) 11:49:35 PM: buildbot version: 20d735efc756356fd09bbc43982bef2018461b10 11:49:35 PM: Fetching cached dependencies 11:49:35 PM: Failed to fetch cache, continuing with build 11:49:35 PM: Starting to prepare the repo for build 11:49:36 PM: No cached dependencies found. Cloning fresh repo 11:49:36 PM: git clone --filter=blob:none https://github.com/kingleoric/astro-directus 11:49:36 PM: Preparing Git Reference refs/heads/master 11:49:37 PM: Parsing package.json dependencies 11:49:38 PM: Starting to install dependencies 11:49:38 PM: Python version set to 3.8 11:49:38 PM: Attempting Ruby version 2.7.2, read from environment 11:49:39 PM: Using Ruby version 2.7.2 11:49:40 PM: Started restoring cached go cache 11:49:40 PM: Finished restoring cached go cache 11:49:40 PM: Installing Go version 1.19.5 (requested 1.19.5) 11:49:45 PM: go version go1.19.5 linux/amd64 11:49:45 PM: Using PHP version 8.0 11:49:46 PM: Downloading and installing node v16.15.1... 11:49:46 PM: Downloading https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.xz... 11:49:46 PM: Computing checksum with sha256sum 11:49:47 PM: Checksums matched! 11:49:48 PM: Now using node v16.15.1 (npm v8.11.0) 11:49:48 PM: Enabling Node.js Corepack 11:49:49 PM: Started restoring cached build plugins 11:49:49 PM: Finished restoring cached build plugins 11:49:49 PM: Started restoring cached corepack dependencies 11:49:49 PM: Finished restoring cached corepack dependencies 11:49:49 PM: jq: error (at <stdin>:70): Cannot iterate over null (null) 11:49:49 PM: No npm workspaces detected 11:49:49 PM: Started restoring cached node modules 11:49:49 PM: Finished restoring cached node modules 11:49:49 PM: Installing npm packages using npm version 8.11.0 11:49:56 PM: added 475 packages, and audited 476 packages in 7s 11:49:56 PM: 206 packages are looking for funding 11:49:56 PM: run `npm fund` for details 11:49:56 PM: found 0 vulnerabilities 11:49:56 PM: npm packages installed 11:49:56 PM: Install dependencies script success 11:49:56 PM: Starting build script 11:49:57 PM: Detected 1 framework(s) 11:49:57 PM: "astro" at version "2.4.5" 11:49:57 PM: Section completed: initializing 11:49:59 PM: 11:49:59 PM: Netlify Build 11:49:59 PM: ──────────────────────────────────────────────────────────────── 11:49:59 PM: 11:49:59 PM: ❯ Version 11:49:59 PM: @netlify/build 29.11.2 11:49:59 PM: 11:49:59 PM: ❯ Flags 11:49:59 PM: baseRelDir: true 11:49:59 PM: buildId: 646005eb22a1e11014ab9291 11:49:59 PM: deployId: 646005eb22a1e11014ab9293 11:49:59 PM: 11:49:59 PM: ❯ Current directory 11:49:59 PM: /opt/build/repo 11:49:59 PM: 11:49:59 PM: ❯ Config file 11:49:59 PM: No config file was defined: using default values. 11:49:59 PM: 11:49:59 PM: ❯ Context 11:49:59 PM: production 11:49:59 PM: 11:49:59 PM: Build command from Netlify app 11:49:59 PM: ──────────────────────────────────────────────────────────────── 11:49:59 PM: 11:49:59 PM: $ npm run build 11:50:00 PM: > astro-directus@0.0.1 build 11:50:00 PM: > astro build 11:50:01 PM: 09:50:01 PM [content] Types generated 469ms 11:50:01 PM: 09:50:01 PM [build] output target: static 11:50:01 PM: 09:50:01 PM [build] Collecting build info... 11:50:01 PM: 09:50:01 PM [build] Completed in 0.76s. 11:50:01 PM: 09:50:01 PM [build] Building static entrypoints... 11:50:03 PM: 09:50:03 PM [build] Completed in 1.59s. 11:50:03 PM: 11:50:03 PM: generating static routes 11:50:03 PM: ▶ src/pages/index.astro 11:50:03 PM: └─ /index.html (+14ms) 11:50:03 PM: λ src/pages/rss.xml.js 11:50:03 PM: └─ /rss.xml (+5ms) 11:50:03 PM: ▶ src/pages/blog/index.astro 11:50:03 PM: TypeError: Cannot read properties of undefined (reading 'type') 11:50:03 PM: at Function.is (file:///opt/build/repo/node_modules/astro/dist/core/errors/errors.js:42:16) 11:50:03 PM: at eventError (file:///opt/build/repo/node_modules/astro/dist/events/error.js:33:32) 11:50:03 PM: at throwAndExit (file:///opt/build/repo/node_modules/astro/dist/cli/index.js:226:41) 11:50:03 PM: at cli (file:///opt/build/repo/node_modules/astro/dist/cli/index.js:211:11) 11:50:03 PM: 11:50:03 PM: "build.command" failed 11:50:03 PM: ──────────────────────────────────────────────────────────────── 11:50:03 PM: 11:50:03 PM: Error message 11:50:03 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1) 11:50:03 PM: 11:50:03 PM: Error location 11:50:03 PM: In Build command from Netlify app: 11:50:03 PM: npm run build 11:50:03 PM: 11:50:03 PM: Resolved config 11:50:03 PM: build: 11:50:03 PM: command: npm run build 11:50:03 PM: commandOrigin: ui 11:50:03 PM: environment: 11:50:03 PM: - NODE_VERSION 11:50:03 PM: publish: /opt/build/repo/dist 11:50:03 PM: publishOrigin: ui 11:50:04 PM: Caching artifacts 11:50:04 PM: Started saving node modules 11:50:04 PM: Finished saving node modules 11:50:04 PM: Started saving build plugins 11:50:04 PM: Finished saving build plugins 11:50:04 PM: Started saving corepack cache 11:50:04 PM: Finished saving corepack cache 11:50:04 PM: Started saving pip cache 11:50:04 PM: Finished saving pip cache 11:50:04 PM: Started saving emacs cask dependencies 11:50:04 PM: Finished saving emacs cask dependencies 11:50:04 PM: Started saving maven dependencies 11:50:04 PM: Finished saving maven dependencies 11:50:04 PM: Started saving boot dependencies 11:50:04 PM: Finished saving boot dependencies 11:50:04 PM: Started saving rust rustup cache 11:50:05 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2) 11:50:04 PM: Finished saving rust rustup cache 11:50:04 PM: Started saving go dependencies 11:50:04 PM: Finished saving go dependencies 11:50:05 PM: Build failed due to a user error: Build script returned non-zero exit code: 2 11:50:05 PM: Failing build: Failed to build site 11:50:05 PM: Finished processing build request in 30.158s
二 SSR模式下不支持axios
没错,在SSR模式下(Astro output: server)使用DirectusJavaScript SDK请求失败
"logs": [
{
"message": [
"08:18:37 AM [ssr] Error: r is not a function\n at vr.request (functionsWorker-0.8088328977428203.js:3406:15)\n at async vr.get (functionsWorker-0.8088328977428203.js:3410:14)\n at async ee.readByQuery (functionsWorker-0.8088328977428203.js:3026:34)\n at async functionsWorker-0.8088328977428203.js:3736:14\n at async eu (functionsWorker-0.8088328977428203.js:1275:11)\n at async da (functionsWorker-0.8088328977428203.js:1630:11)\n at async ft.yn (functionsWorker-0.8088328977428203.js:2202:135)\n at async ft.render (functionsWorker-0.8088328977428203.js:2173:17)\n at async Object.fetch (functionsWorker-0.8088328977428203.js:3946:15) (x7)"
],
"level": "error",
"timestamp": 1685002717190
}
]看起来这是一个请求失败的错误,于是我把sdk的请求代码
const directus = await getDirectusClient()
const response = await directus.items("articles").readByQuery({
...
})使用fetch替换
const response = await fetch('...').then((response) => response.json())重新部署后发现成功运行。
打开@directus\sdk源码看到请求使用的是axios,于是去google求证了一下,结果发现cloudflare pages和workers使用axios请求都会产生问题,参考这篇文章:
It seems node-mailjet would be incompatible with cloudflare workers.
One of its dependencies is axios, which is definitely incompatible with the cf workers.Fortunately, it's possible to access the API without the library, albeit a bit more work, but this makes it platform agnostic. The example below uses a the
fetchAPI.
以及这篇
Node APIs don’t work on Workers.
Axios use a lot of Node-native APIs so it will not work, I think you’d basically need to rewrite it to get it to work.Use fetch instead: https://developers.cloudflare.com/workers/runtime-apis/fetch/
此问题最终解决方法就是使用fetch替换。
Axios和Fetch有什么不一样?
Axios是对XMLHttpRequest的封装,Fetch是一种新的获取资源的接口方式,并不是对XMLHttpRequest的封装,两者最大的不同点在于Fetch是浏览器原生支持,而Axios需要引入Axios库。
三 编译错误: ✘ [ERROR] Could not resolve "xxx"
2023-05-27T11:49:53.253905Z ✘ [ERROR] Could not resolve "url"
2023-05-27T11:49:53.254164Z
2023-05-27T11:49:53.254298Z dist/$server_build/chunks/pages/rss.xml.js.ce6a99d8.mjs:4:7:
2023-05-27T11:49:53.254421Z 4 │ import 'url';
2023-05-27T11:49:53.254536Z ╵ ~~~~~
2023-05-27T11:49:53.254647Z
2023-05-27T11:49:53.254773Z The package "url" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.254887Z
2023-05-27T11:49:53.255001Z ✘ [ERROR] Could not resolve "module"
2023-05-27T11:49:53.255108Z
2023-05-27T11:49:53.25521Z dist/$server_build/chunks/pages/rss.xml.js.ce6a99d8.mjs:16:7:
2023-05-27T11:49:53.25532Z 16 │ import 'module';
2023-05-27T11:49:53.255438Z ╵ ~~~~~~~~
2023-05-27T11:49:53.255545Z
2023-05-27T11:49:53.255645Z The package "module" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.255764Z
2023-05-27T11:49:53.255873Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.25598Z
2023-05-27T11:49:53.256085Z dist/$server_build/chunks/pages/rss.xml.js.ce6a99d8.mjs:17:7:
2023-05-27T11:49:53.256185Z 17 │ import 'path';
2023-05-27T11:49:53.256292Z ╵ ~~~~~~
2023-05-27T11:49:53.256401Z
2023-05-27T11:49:53.256506Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.256607Z
2023-05-27T11:49:53.257532Z ✘ [ERROR] Could not resolve "url"
2023-05-27T11:49:53.25778Z
2023-05-27T11:49:53.257929Z dist/$server_build/chunks/pages/_...slug_.astro.df17ddfc.mjs:2:22:
2023-05-27T11:49:53.258041Z 2 │ import * as url2 from 'url';
2023-05-27T11:49:53.258165Z ╵ ~~~~~
2023-05-27T11:49:53.25828Z
2023-05-27T11:49:53.258394Z The package "url" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.258506Z
2023-05-27T11:49:53.258613Z ✘ [ERROR] Could not resolve "module"
2023-05-27T11:49:53.258733Z
2023-05-27T11:49:53.25884Z dist/$server_build/chunks/pages/_...slug_.astro.df17ddfc.mjs:7:20:
2023-05-27T11:49:53.258948Z 7 │ import module2 from 'module';
2023-05-27T11:49:53.259068Z ╵ ~~~~~~~~
2023-05-27T11:49:53.259174Z
2023-05-27T11:49:53.259274Z The package "module" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.259441Z
2023-05-27T11:49:53.259552Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.259658Z
2023-05-27T11:49:53.259785Z dist/$server_build/chunks/pages/_...slug_.astro.df17ddfc.mjs:8:18:
2023-05-27T11:49:53.259889Z 8 │ import path2 from 'path';
2023-05-27T11:49:53.259993Z ╵ ~~~~~~
2023-05-27T11:49:53.260097Z
2023-05-27T11:49:53.260199Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.2603Z
2023-05-27T11:49:53.274799Z ✘ [ERROR] Could not resolve "url"
2023-05-27T11:49:53.275018Z
2023-05-27T11:49:53.275143Z dist/$server_build/chunks/using-mdx.81e20eb0.mjs:11:7:
2023-05-27T11:49:53.275253Z 11 │ import 'url';
2023-05-27T11:49:53.275361Z ╵ ~~~~~
2023-05-27T11:49:53.275481Z
2023-05-27T11:49:53.275586Z The package "url" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.275701Z
2023-05-27T11:49:53.275814Z ✘ [ERROR] Could not resolve "module"
2023-05-27T11:49:53.27592Z
2023-05-27T11:49:53.276023Z dist/$server_build/chunks/using-mdx.81e20eb0.mjs:15:7:
2023-05-27T11:49:53.276194Z 15 │ import 'module';
2023-05-27T11:49:53.276313Z ╵ ~~~~~~~~
2023-05-27T11:49:53.276428Z
2023-05-27T11:49:53.276534Z The package "module" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.276667Z
2023-05-27T11:49:53.276807Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.276935Z
2023-05-27T11:49:53.277044Z dist/$server_build/chunks/using-mdx.81e20eb0.mjs:16:7:
2023-05-27T11:49:53.27715Z 16 │ import 'path';
2023-05-27T11:49:53.27902Z ╵ ~~~~~~
2023-05-27T11:49:53.279188Z
2023-05-27T11:49:53.279307Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.279424Z
2023-05-27T11:49:53.279535Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.279643Z
2023-05-27T11:49:53.279766Z node_modules/@proload/core/lib/esm/index.mjs:2:48:
2023-05-27T11:49:53.279879Z 2 │ import { join, dirname, extname, resolve } from "path";
2023-05-27T11:49:53.279983Z ╵ ~~~~~~
2023-05-27T11:49:53.280085Z
2023-05-27T11:49:53.280189Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.280291Z
2023-05-27T11:49:53.2804Z ✘ [ERROR] Could not resolve "fs"
2023-05-27T11:49:53.28051Z
2023-05-27T11:49:53.280613Z node_modules/@proload/core/lib/esm/index.mjs:5:52:
2023-05-27T11:49:53.280731Z 5 │ import { existsSync, readdir, readFile, stat } from "fs";
2023-05-27T11:49:53.280851Z ╵ ~~~~
2023-05-27T11:49:53.280957Z
2023-05-27T11:49:53.281157Z The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.281394Z
2023-05-27T11:49:53.281536Z ✘ [ERROR] Could not resolve "util"
2023-05-27T11:49:53.28165Z
2023-05-27T11:49:53.281772Z node_modules/@proload/core/lib/esm/index.mjs:6:26:
2023-05-27T11:49:53.281879Z 6 │ import { promisify } from "util";
2023-05-27T11:49:53.281986Z ╵ ~~~~~~
2023-05-27T11:49:53.282089Z
2023-05-27T11:49:53.282192Z The package "util" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.282296Z
2023-05-27T11:49:53.282405Z ✘ [ERROR] Could not resolve "module"
2023-05-27T11:49:53.282513Z
2023-05-27T11:49:53.28401Z node_modules/@proload/core/lib/esm/index.mjs:7:30:
2023-05-27T11:49:53.28417Z 7 │ import { createRequire } from "module";
2023-05-27T11:49:53.284287Z ╵ ~~~~~~~~
2023-05-27T11:49:53.284404Z
2023-05-27T11:49:53.284515Z The package "module" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.284623Z
2023-05-27T11:49:53.286535Z ✘ [ERROR] Could not resolve "fs"
2023-05-27T11:49:53.287176Z
2023-05-27T11:49:53.287346Z node_modules/tsm/require.js:1:41:
2023-05-27T11:49:53.287481Z 1 │ ...";const{readFileSync}=require("fs"),{extname}=require("path"),ts...
2023-05-27T11:49:53.287709Z ╵ ~~~~
2023-05-27T11:49:53.287848Z
2023-05-27T11:49:53.288119Z The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.288344Z
2023-05-27T11:49:53.288567Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.288708Z
2023-05-27T11:49:53.289015Z node_modules/tsm/require.js:1:65:
2023-05-27T11:49:53.289151Z 1 │ ...uire("fs"),{extname}=require("path"),tsm=require("./utils"),load...
2023-05-27T11:49:53.289267Z ╵ ~~~~~~
2023-05-27T11:49:53.289447Z
2023-05-27T11:49:53.289562Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.289673Z
2023-05-27T11:49:53.289822Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.289931Z
2023-05-27T11:49:53.290034Z node_modules/escalade/dist/index.mjs:1:33:
2023-05-27T11:49:53.290136Z 1 │ import { dirname, resolve } from 'path';
2023-05-27T11:49:53.290241Z ╵ ~~~~~~
2023-05-27T11:49:53.290349Z
2023-05-27T11:49:53.290699Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.290852Z
2023-05-27T11:49:53.290967Z ✘ [ERROR] Could not resolve "fs"
2023-05-27T11:49:53.291077Z
2023-05-27T11:49:53.291181Z node_modules/escalade/dist/index.mjs:2:30:
2023-05-27T11:49:53.291344Z 2 │ import { readdir, stat } from 'fs';
2023-05-27T11:49:53.291617Z ╵ ~~~~
2023-05-27T11:49:53.291763Z
2023-05-27T11:49:53.291875Z The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.291978Z
2023-05-27T11:49:53.292079Z ✘ [ERROR] Could not resolve "util"
2023-05-27T11:49:53.29218Z
2023-05-27T11:49:53.292279Z node_modules/escalade/dist/index.mjs:3:26:
2023-05-27T11:49:53.292386Z 3 │ import { promisify } from 'util';
2023-05-27T11:49:53.292498Z ╵ ~~~~~~
2023-05-27T11:49:53.292676Z
2023-05-27T11:49:53.29281Z The package "util" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.292923Z
2023-05-27T11:49:53.293026Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.293129Z
2023-05-27T11:49:53.293232Z node_modules/i18next-fs-backend/esm/path.cjs:2:21:
2023-05-27T11:49:53.293335Z 2 │ var path = require('path')
2023-05-27T11:49:53.29345Z │ ~~~~~~
2023-05-27T11:49:53.293645Z ╵ "./path"
2023-05-27T11:49:53.293875Z
2023-05-27T11:49:53.294033Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.294186Z
2023-05-27T11:49:53.294332Z ✘ [ERROR] Could not resolve "fs"
2023-05-27T11:49:53.294505Z
2023-05-27T11:49:53.294655Z node_modules/tsm/node_modules/esbuild/lib/main.js:1672:17:
2023-05-27T11:49:53.294842Z 1672 │ var fs = require("fs");
2023-05-27T11:49:53.294998Z ╵ ~~~~
2023-05-27T11:49:53.295141Z
2023-05-27T11:49:53.295325Z The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.295524Z
2023-05-27T11:49:53.295757Z ✘ [ERROR] Could not resolve "os"
2023-05-27T11:49:53.295915Z
2023-05-27T11:49:53.296098Z node_modules/tsm/node_modules/esbuild/lib/main.js:1673:17:
2023-05-27T11:49:53.296301Z 1673 │ var os = require("os");
2023-05-27T11:49:53.296469Z ╵ ~~~~
2023-05-27T11:49:53.296643Z
2023-05-27T11:49:53.296776Z The package "os" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.296885Z
2023-05-27T11:49:53.297013Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.297128Z
2023-05-27T11:49:53.297243Z node_modules/tsm/node_modules/esbuild/lib/main.js:1674:19:
2023-05-27T11:49:53.297363Z 1674 │ var path = require("path");
2023-05-27T11:49:53.297543Z ╵ ~~~~~~
2023-05-27T11:49:53.297681Z
2023-05-27T11:49:53.297822Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.29794Z
2023-05-27T11:49:53.298089Z ✘ [ERROR] Could not resolve "fs"
2023-05-27T11:49:53.298215Z
2023-05-27T11:49:53.298328Z node_modules/i18next-fs-backend/esm/fs.cjs:2:18:
2023-05-27T11:49:53.298446Z 2 │ var f = require('fs')
2023-05-27T11:49:53.298556Z │ ~~~~
2023-05-27T11:49:53.298669Z ╵ "./fs"
2023-05-27T11:49:53.298799Z
2023-05-27T11:49:53.298905Z The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.299012Z
2023-05-27T11:49:53.299126Z ✘ [ERROR] Could not resolve "path"
2023-05-27T11:49:53.299229Z
2023-05-27T11:49:53.29933Z node_modules/tsm/utils.js:1:36:
2023-05-27T11:49:53.299442Z 1 │ ...rict";const{resolve}=require("path"),{existsSync}=require("fs");...
2023-05-27T11:49:53.299733Z ╵ ~~~~~~
2023-05-27T11:49:53.299887Z
2023-05-27T11:49:53.300013Z The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.300142Z
2023-05-27T11:49:53.30035Z ✘ [ERROR] Could not resolve "fs"
2023-05-27T11:49:53.300478Z
2023-05-27T11:49:53.300599Z node_modules/tsm/utils.js:1:65:
2023-05-27T11:49:53.300743Z 1 │ ...("path"),{existsSync}=require("fs");exports.$defaults=function(l...
2023-05-27T11:49:53.300871Z ╵ ~~~~
2023-05-27T11:49:53.300986Z
2023-05-27T11:49:53.301098Z The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.301226Z
2023-05-27T11:49:53.301362Z ✘ [ERROR] Could not resolve "module"
2023-05-27T11:49:53.301586Z
2023-05-27T11:49:53.301764Z node_modules/@proload/core/lib/esm/requireOrImport.mjs:2:30:
2023-05-27T11:49:53.301911Z 2 │ import { createRequire } from 'module';
2023-05-27T11:49:53.302053Z ╵ ~~~~~~~~
2023-05-27T11:49:53.302192Z
2023-05-27T11:49:53.30234Z The package "module" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.302504Z
2023-05-27T11:49:53.302642Z ✘ [ERROR] Could not resolve "url"
2023-05-27T11:49:53.302807Z
2023-05-27T11:49:53.302944Z node_modules/@proload/core/lib/esm/requireOrImport.mjs:3:30:
2023-05-27T11:49:53.303075Z 3 │ import { pathToFileURL } from 'url';
2023-05-27T11:49:53.303232Z ╵ ~~~~~
2023-05-27T11:49:53.303368Z
2023-05-27T11:49:53.30357Z The package "url" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.30374Z
2023-05-27T11:49:53.303881Z ✘ [ERROR] Could not resolve "child_process"
2023-05-27T11:49:53.304015Z
2023-05-27T11:49:53.304161Z node_modules/tsm/node_modules/esbuild/lib/main.js:1856:28:
2023-05-27T11:49:53.304296Z 1856 │ var child_process = require("child_process");
2023-05-27T11:49:53.304428Z ╵ ~~~~~~~~~~~~~~~
2023-05-27T11:49:53.304566Z
2023-05-27T11:49:53.304773Z The package "child_process" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.304912Z
2023-05-27T11:49:53.305046Z ✘ [ERROR] Could not resolve "crypto"
2023-05-27T11:49:53.305182Z
2023-05-27T11:49:53.305315Z node_modules/tsm/node_modules/esbuild/lib/main.js:1857:21:
2023-05-27T11:49:53.305444Z 1857 │ var crypto = require("crypto");
2023-05-27T11:49:53.305575Z ╵ ~~~~~~~~
2023-05-27T11:49:53.305718Z
2023-05-27T11:49:53.305854Z The package "crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.306001Z
2023-05-27T11:49:53.306136Z ✘ [ERROR] Could not resolve "tty"
2023-05-27T11:49:53.306274Z
2023-05-27T11:49:53.306408Z node_modules/tsm/node_modules/esbuild/lib/main.js:1861:18:
2023-05-27T11:49:53.306538Z 1861 │ var tty = require("tty");
2023-05-27T11:49:53.306668Z ╵ ~~~~~
2023-05-27T11:49:53.306976Z
2023-05-27T11:49:53.307134Z The package "tty" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
2023-05-27T11:49:53.307279Z
2023-05-27T11:49:53.448762Z error Could not resolve "url"
2023-05-27T11:49:53.44908Z File:
2023-05-27T11:49:53.449222Z dist/$server_build/chunks/pages/_...slug_.astro.df17ddfc.mjs:2:22
2023-05-27T11:49:53.449335Z Code:
2023-05-27T11:49:53.449458Z 1 | import i18next, { t, changeLanguage } from 'i18next';
2023-05-27T11:49:53.449597Z > 2 | import * as url2 from 'url';
2023-05-27T11:49:53.449728Z | ^
2023-05-27T11:49:53.449846Z 3 | import '@proload/core';
2023-05-27T11:49:53.449952Z 4 | import '@proload/plugin-tsm';
2023-05-27T11:49:53.450077Z 5 | import { c as createAstro, a as createComponent, r as renderTemplate, b as addAttribute, m as maybeRenderHead, s as spreadAttributes, d as renderSlot, e as renderComponent, u as unescapeHTML, F as Fragment, f as createCollectionToGlobResultMap, g as createGetCollection, h as renderHead } from '../astro.dd9e8298.mjs';
2023-05-27T11:49:53.483197Z Failed: build command exited with code: 1
2023-05-27T11:49:54.314848Z Failed: error occurred while running build command解决方法
把output的模式改为hybrid
output: 'hybrid',
experimental: {
hybridOutput: true,
},并在CloudFlare Pages控制台找到Compatibility flag,并设置为nodejs_compat
