我正在尝试为 Netlify(开发)构建一个 astro 项目,但是我不断收到此错误:
TypeError: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
at new NodeError (node:internal/errors:393:5)
at createRequire (node:internal/modules/cjs/loader:1278:11)
at .netlify/functions-internal/chunks/image-pool.f66f99fb.mjs (/Users/user/sauce/project/.netlify/functions-internal/chunks/image-pool.f66f99fb.mjs:135:20)
at __init (/Users/user/sauce/project/.netlify/functions-serve/entry/src/.netlify/functions-internal/entry.js:37:59)
at /Users/user/sauce/project/.netlify/functions-internal/entry.mjs:1917:32
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_INVALID_ARG_VALUE'
}
Node.js v18.12.1
/Users/user/sauce/project/.netlify/functions-serve/entry/src/.netlify/functions-internal/entry.js:37:59):
return fn2 && (res = (0, fn2[__getOwnPropNames(fn2)[0]])(fn2 = 0)), res;
};
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all2) => {
for (var name in all2)
__defProp(target, name, { get: all2[name], enumerable: true });
};
var __copyProps = (to2, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to2, key) && key !== except)
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to2;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/boolean/build/lib/boolean.js
var require_boolean = __commonJS({
"node_modules/boolean/build/lib/boolean.js"(exports) {
Package.json:
{
"name": "@example/basics",
"type": "module",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/alpinejs": "^0.1.2",
"@astrojs/image": "^0.11.0",
"@astrojs/mdx": "^0.11.5",
"@astrojs/netlify": "^1.3.0",
"@astrojs/sitemap": "^1.0.0",
"@astrojs/tailwind": "^2.1.1",
"@datadog/browser-rum": "^4.28.1",
"@fontsource/inter": "^4.5.14",
"@sentry/browser": "^7.28.1",
"@sentry/tracing": "^7.28.1",
"@types/alpinejs": "^3.0.0",
"alpinejs": "^3.0.0",
"astro": "^1.6.0",
"astro-feather-icons": "^1.0.2",
"astro-google-analytics": "^1.0.2",
"astro-icon": "^0.8.0",
"astro-netlify-cms": "^0.0.1",
"astro-seo": "^0.6.0",
"node-fetch": "^3.3.0",
"tailwindcss": "^3.0.24"
},
"engines": {
"node": ">=16.0.0 <19.0.0"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.7"
}
}
直接在 Astro 上构建网站是可行的,但是当部署到 Netlify(开发或云)时,尝试加载页面时会出现此错误。 然而,Netlify Content Manager 端点能够加载。
事实证明,依赖项之一 @astrojs/image 与 Netlify 不兼容。删除依赖关系并引用各个位置后,该网站现在可以运行了! :)