ali-oss icon indicating copy to clipboard operation
ali-oss copied to clipboard

Bug: Nuxt3+ts项目 打包报错

Open ifredom opened this issue 1 year ago • 8 comments

Nuxt3 +ts 项目,导入ali-oss,一旦执行 pnpm run build,就会出现打包错误。

  • 在这里其他人也有复现此问题: https://github.com/nuxt/nuxt/issues/19017
  • Nuxt3 使用 rollup-plugin作为打包工具,对于 *.ts 文件无法解析

image

ifredom avatar Oct 08 '23 04:10 ifredom

遇到一样的问题

zichen4479 avatar Oct 08 '23 14:10 zichen4479

nitro: { rollupConfig: { external: ['ali-oss'], plugins: [ nodeResolve({ exportConditions: ['node'], extensions: ['.mjs', '.node'], }), ], }, node: true, }, 排除的话,又run不起来,缺少依赖

zichen4479 avatar Oct 08 '23 14:10 zichen4479

nitro: { rollupConfig: { external: ['ali-oss'], plugins: [ nodeResolve({ exportConditions: ['node'], extensions: ['.mjs', '.node'], }), ], }, node: true, }, 排除的话,又run不起来,缺少依赖

是的,排除后,打包部署到服务器无法运行。没找到办法,你解决了吗

ifredom avatar Oct 09 '23 09:10 ifredom

q: 1950735817

ifredom avatar Oct 09 '23 09:10 ifredom

同一个问题

sansui-orz avatar Oct 25 '23 13:10 sansui-orz

image image

this不是保留关键字吗?我真是服了呀

sansui-orz avatar Oct 25 '23 13:10 sansui-orz

两种办法。

第一种:让ali-oss参与构建过程,这样就能将ts编译成js。

export default defineNuxtConfig({
  build: {
    transpile: ['ali-oss']
  }
})

第二种,使用CDN

export default defineNuxtConfig({
  app: {
    head: {
      script: [
        { src: "http://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.1.min.js" }
      ]
    },
})

ajh99990 avatar Oct 28 '23 03:10 ajh99990

我在 Windows 系统上构建时出现相同的错误,但在 docker 容器内构建却是正常的,原因未知,可能与 Windows 路径有关。

FROM node:latest AS builder
WORKDIR /root
RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pnpm
COPY .npmrc .
COPY package.json .
RUN pnpm install --prod
COPY . .
RUN pnpm build

FROM node:latest
WORKDIR /root
COPY --from=builder /root/.output .
CMD node ./server/index.mjs

fisschl avatar Mar 12 '24 08:03 fisschl