Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Nuxt3+ts项目 打包报错 #1258

Open
ifredom opened this issue Oct 8, 2023 · 8 comments
Open

Bug: Nuxt3+ts项目 打包报错 #1258

ifredom opened this issue Oct 8, 2023 · 8 comments

Comments

@ifredom
Copy link

ifredom commented Oct 8, 2023

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

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

image

@zichen4479
Copy link

遇到一样的问题

@zichen4479
Copy link

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

@ifredom
Copy link
Author

ifredom commented Oct 9, 2023

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

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

@ifredom
Copy link
Author

ifredom commented Oct 9, 2023

q: 1950735817

@sansui-orz
Copy link

同一个问题

@sansui-orz
Copy link

image
image

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

@ajh99990
Copy link

两种办法。

第一种:让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" }
      ]
    },
})

@fisschl
Copy link

fisschl commented Mar 12, 2024

我在 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants