Typescript: Only declares and type imports are allowed inside declare module

Created on 13 Nov 2019  路  11Comments  路  Source: nuxt/typescript

According to the official plugins tutorial, I just copied the code block into the plugins folder, then added the plugin in nuxt.config.js and reported an error.
Version: [email protected]
Here is the screenshot:
image

image

bug build

Most helpful comment

@kevinmarrec This is not associated with an upgrade to TypeScript 3.7 as I can replicate it with 3.6.

The issue is the babel-eslint parser, which is installed out of the box by create-nuxt-app, and which has a number of problems with TypeScript. The first thing I do in any new project is replace it:

yarn add --dev @typescript-eslint/parser

... and then edit .eslintrc.js:

module.exports = {
  ...
  parserOptions: {
    parser: "@typescript-eslint/parser"
  },
};

All 11 comments

@kevinmarrec

@lenvonsam try typescript 3.6 as quick workardound, I saw some issues related to nuxt and typescript 3.7. LMK if it helped you.

@lenvonsam Can you confirm it works with TypeScript 3.6 ? Thanks !

Should the module type declarations be in a myPlugin.d.ts?

Yes. This is a docs issue, not a build one.

Though note that it is an eslint error rather than a TypeScript build error. See here for example.

Still, I would think you want to put declarations in .d.ts files. I'll put in a PR, though happy to be overruled if it's simpler.

@danielroe Can the error be fixed with some eslint rule ? The thing is that this lint error doesn't show up with 3.6

@kevinmarrec This is not associated with an upgrade to TypeScript 3.7 as I can replicate it with 3.6.

The issue is the babel-eslint parser, which is installed out of the box by create-nuxt-app, and which has a number of problems with TypeScript. The first thing I do in any new project is replace it:

yarn add --dev @typescript-eslint/parser

... and then edit .eslintrc.js:

module.exports = {
  ...
  parserOptions: {
    parser: "@typescript-eslint/parser"
  },
};

Repro.

  1. Clone & install deps
  2. Run eslint:
    bash yarn eslint '**/*.{vue,ts,js}'
  3. Fix issue by uncommenting parser in .eslintrc.js.
  4. Re-run eslint.

I propose adding some info in docs about correct eslint configuration, if it doesn't already exist.
Edit: docs are correct :smiley:

Alright so it never really has been an issue, right ? Also there's https://github.com/nuxt/create-nuxt-app/pull/328 nearly ready that will fix it around CNA (https://github.com/nuxt/create-nuxt-app/pull/328/files#diff-9fd823e96cf162b0ef4dd75d806e4c4eR12)

Can we close this then ?

Agreed. Yes, this can be closed.

Was this page helpful?
0 / 5 - 0 ratings