首页 > 解决方案 > How do I add a typescript module to Nuxt Config?

问题描述

How do I add the typescript file to my build? It is a configuration file.

To reproduce

% npm create nuxt-app play-ts-nuxt   

  create-nuxt-app v3.6.0
✨  Generating Nuxt.js project in play-ts-nuxt
? Project name: play-ts-nuxt
? Programming language: TypeScript
? Package manager: Npm
? UI framework: Buefy
? Nuxt.js modules: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Linting tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Testing framework: Jest
? Rendering mode: Universal (SSR / SSG)
? Deployment target: Server (Node.js hosting)
? Development tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Continuous integration: None
? Version control system: Git

Then convert nuxt.config.js to nuxt.config.ts

I changed some require code

build: {
    vendor: [],
    publicPath: `/${require('./secrets.json').NODE_ENV}/_nuxt/` // <= add the path to the cached files
},

To typescript

import envConfiguration from './env-configuration'

build: {
    publicPath: `/${envConfiguration.NODE_ENV}/_nuxt/` // <= add the path to the cached files
},

I get an error that the env-configuration.ts file is not in .build. It is in the root of the project, how do I add it to the build?

Error: Cannot find module './env-configuration'
Require stack:
  - ...uploader/.build/nuxt.config.js

标签: typescriptnuxt.js

解决方案


推荐阅读