Nuxt Typescript与Custom Server Framework:TypeError:[Babel]

问题描述 投票:0回答:1

[我一直在努力使Nuxt Typescript在自定义服务器框架(Typescript Node / Express)上以编程方式工作,但是不能。

我的猜测是,有一些加载程序或可转换的配置可以解决此问题,但搜索没有发现任何问题。

基本文件结构是...

- private/ --> Custom server framework
- public/ --> Nuxt

使用node --require ts-node/register --require tsconfig-paths/register private/index.ts构建时的错误

your-service-name_1  | Module build failed (from ./node_modules/babel-loader/lib/index.js):
your-service-name_1  | TypeError: [BABEL] /root/dist/client.js: (0 , _private.makeAccessor) is not a function (While processing: "/root/node_modules/@nuxt/babel-preset-app/src/index.js")
your-service-name_1  |     at Object.<anonymous> (/root/node_modules/regenerator-transform/lib/meta.js:17:35)
your-service-name_1  |     at Module._compile (internal/modules/cjs/loader.js:701:30)
your-service-name_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
your-service-name_1  |     at Module.load (internal/modules/cjs/loader.js:600:32)
your-service-name_1  |     at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
your-service-name_1  |     at Function.Module._load (internal/modules/cjs/loader.js:531:3)
your-service-name_1  |     at Module.require (internal/modules/cjs/loader.js:637:17)
your-service-name_1  |     at require (internal/modules/cjs/helpers.js:22:18)
your-service-name_1  |     at Object.<anonymous> (/root/node_modules/regenerator-transform/lib/emit.js:11:36)
your-service-name_1  |     at Module._compile (internal/modules/cjs/loader.js:701:30)
your-service-name_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
your-service-name_1  |     at Module.load (internal/modules/cjs/loader.js:600:32)
your-service-name_1  |     at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
your-service-name_1  |     at Function.Module._load (internal/modules/cjs/loader.js:531:3)
your-service-name_1  |     at Module.require (internal/modules/cjs/loader.js:637:17)
your-service-name_1  |     at require (internal/modules/cjs/helpers.js:22:18)
your-service-name_1  | 
your-service-name_1  |  @ multi eventsource-polyfill webpack-hot-middleware/client?reload=true&timeout=30000&ansiColors=&overlayStyles=&name=client&path=/__webpack_hmr/client ./dist/client.js
// private/server.ts

// called from private/index.ts
  public async start(): Promise<number> {
    // Init Nuxt.js
    // Make sure to wait for Nuxt to load @nuxt/typescript-build before proceeding
    const nuxtConfig = await import('../nuxt.config')
    const nuxt = new Nuxt(nuxtConfig)
    await nuxt.ready()

    if (this.config.server.environment === 'local') {
      const builder = new Builder(nuxt)
      await builder.build()
    }

这里是nuxt.config.jstsconfig.nuxt.jso中的相关设置。

// nuxt.config.js

module.exports = {
  buildDir: 'dist',
  srcDir: 'public',
  mode: 'universal', 
  plugins: [
  ],
  buildModules: [
    '@nuxt/typescript-build',
    '@nuxtjs/vuetify'
  ],
  modules: [
    '@nuxtjs/axios',
  ],
  typescript: {
    tslint: 'tslint.json',
    tsconfig: 'tsconfig.nuxt.json'
  },
  build: {
    transpile: [
      'vuex-module-decorators'
    ],
    extend(config, ctx) {

    }
  }
}


// tsconfig.nuxt.json
{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "allowJs": false,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "noImplicitAny": false,
    "lib": [
      "esnext",
      "esnext.asynciterable",
      "dom"
    ],
    "baseUrl": ".",
    "paths": {
      "@config": [
        "configs/index.ts"
      ],
      "@enum": [
        "shared/types/enum"
      ],
      "@interface": [
        "shared/types/interface"
      ]
    } 
  },
  "exclude": [
    "./build",
    "./configs",
    "./node_modules",
    "./private",
    "./test"
  ]
}
typescript webpack nuxt.js babel-loader ts-node
1个回答
0
投票

找出我缺少一个插件。

    plugins: [
      new TsconfigPathsWebpackPlugin()
    ],
© www.soinside.com 2019 - 2024. All rights reserved.