You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Expo+Next.js构建失败:AccessibilityInfo模块导入错误

Next.js 构建失败:Cannot use import statement outside a module 错误(AccessibilityInfo 导入问题)

尝试使用yarn next build构建应用时,收集react-native\index.js的页面数据失败,原因是AccessibilityInfo的导入问题,触发常见错误Cannot use import statement outside a module。随后收集/calculator页面数据时也出现相同错误。已检查转译包及RN导入顺序,但无法确认问题所在。以下是相关配置文件,如需其他信息可补充提供。


错误信息

info  - Linting and checking validity of types
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data ..C:\Users\S\Documents\Projects\Sundberegn\node_modules\react-native\index.js:14
import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1094:15)
    at Module._compile (node:internal/modules/cjs/loader:1129:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
    at Module.load (node:internal/modules/cjs/loader:1043:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1067:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\S\Documents\Projects\Sundberegn\node_modules\react-native-fit-image\dist\FitImage.js:24:22)
    at Module._compile (node:internal/modules/cjs/loader:1165:14)

> Build error occurred
Error: Failed to collect page data for /calculator
    at C:\Users\S\Documents\Projects\Sundberegn\node_modules\next\dist\build\utils.js:963:15
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'Error'
}
error Command failed with exit code 1.

Next.config.js

const { withExpo } = require("@expo/next-adapter");
const withFonts = require("next-fonts");

/** @type {import('next').NextConfig} */
const nextConfig = withExpo(
    {
        reactStrictMode: true,
        swcMinify: true,
        transpilePackages: [
            "react-native",
            "expo",
            "expo-linear-gradient",
            "expo-font",
            "react-native-svg",
            "lucide-react-native",
            "prop-types",
            "react-native-markdown-display",
            
            // Add more React Native / Expo packages here...
        ],
        experimental: {
            forceSwcTransforms: true,
        },
    },
    withFonts({
        projectRoot: __dirname,
    }),
);

module.exports = nextConfig;

Package.json

{
  "dependencies": {
    "expo": "^47.0.0",
    "expo-font": "~11.0.1",
    "expo-linear-gradient": "~12.0.1",
    "lucide-react-native": "^0.115.0",
    "next": "~13.1.1",
    "next-fonts": "^1.5.1",
    "prop-types": "^15.8.1",
    "react": "18.1.0",
    "react-dom": "18.1.0",
    "react-native": "0.70.5",
    "react-native-markdown-display": "^7.0.0-alpha.2",
    "react-native-svg": "13.4.0",
    "react-native-web": "~0.18.7"
  },
  "devDependencies": {
    "@babel/core": "^7.19.3",
    "@expo/next-adapter": "~5.0.0"
  },
  "scripts": {
    "start": "next dev",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "build": "next build"
  },
  "version": "1.0.0",
  "private": true,
  "name": "sundberegn"
}

内容的提问来源于stack exchange,提问作者Stefan Andersen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 12:15:42