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

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

Open
ayelsew opened this issue Aug 30, 2020 · 1 comment

Comments

@ayelsew
Copy link

ayelsew commented Aug 30, 2020

"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

> [email protected] 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! [email protected] grunt: `grunt`
npm ERR! Exit status 3
npm ERR! 
npm ERR! Failed at the [email protected] 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

@nycdotnet
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants