Skip to content

error TS2732 ...Consider using '--resolveJsonModule' to import module with '.json' extension #445

Description

@ayelsew
"grunt": "^1.3.0",
"grunt-ts": "^6.0.0-beta.22",
"typescript": "^3.9.7"

I'm trying to transpile my code typescript using grunt-ts with tsconfig.file. When I run the command npm run grunt the follow error was shown:

➜  backend git:(master) ✗ npm run grunt

> backend@1.0.0 grunt /home/leydev/MEGAsync/Projects/blog/backend
> grunt

Running "ts:default" (ts) task
Compiling...
Using tsc v3.9.7
src/routers/schemas/index.ts(1,22): error TS2732: Cannot find module './postUser.schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
src/routers/schemas/index.ts(2,27): error TS2732: Cannot find module './patchUserById.schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
src/routers/schemas/index.ts(3,22): error TS2732: Cannot find module './posts/postPost.schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
src/routers/schemas/index.ts(4,27): error TS2732: Cannot find module './posts/patchPostById.schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
src/routers/schemas/index.ts(5,25): error TS2732: Cannot find module './auth/postAuthAPI.schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension

>> 5 non-emit-preventing type warnings  
>> Error: tsc return code: 2
Warning: Task "ts:default" failed. Use --force to continue.

Aborted due to warnings.
npm ERR! code ELIFECYCLE
npm ERR! errno 3
npm ERR! backend@1.0.0 grunt: `grunt`
npm ERR! Exit status 3
npm ERR! 
npm ERR! Failed at the backend@1.0.0 grunt script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/leydev/.npm/_logs/2020-08-30T05_44_28_407Z-debug.log

In tsconfig.json already has the option resolveJsonModule, but was ignored.

{
    "compilerOptions": {
        "module": "commonjs",
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "target": "ES5",
        "allowJs": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "rootDir": "src",
        "strict": true
    },
    "include": [
        "src/**/*",
        "src/**/*.json"
    ],
    "exclude": [
        "node_modules",
        "**/*.test.ts",
        "jest.config.js"
    ]
}

This is the gruntfile.js:

module.exports = (grunt) => {
  grunt.initConfig({
    ts: {
      default: {
        tsconfig: './tsconfig.json',
      },
    },
  });
  grunt.loadNpmTasks('grunt-ts');
  grunt.registerTask('default', ['ts']);
};

If I run only tsc, the process runs successfully

Activity

  1. nycdotnet commented on Aug 30, 2020

    @nycdotnet
    Contributor

    in the readme there is a way to pass tsconfig as an object. What you want to do is pass it that way in your Gruntfile and use passthrough true. The docs have the exact syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions