The50
The50

Reputation: 1178

Vue.js + TypeScript importing plain js function

I am trying to import external JS function from separate file into my Vue.js app which is running on TypeScript.

products_table.js

function init_products_table() {
    console.log('test')
}

export {init_products_table as initProductsTable}

And I import it into my Vue component like this:

import { initProductsTable } from '../../products_table.js'

And I get this compile error:

TS7016: Could not find a declaration file for module '../../products_table.js'.

Upvotes: 2

Views: 3987

Answers (1)

ag-dev
ag-dev

Reputation: 243

First if you use TS with Vue.JS you should enable JS in your 'tsconfig.json' file. After some recommendation:

  • importing a JS file into TS is a bit counterproductive, I advise you to code your external function in TS directly, this can avoid future conflicts.
  • when importing you don't have to give the file type. Here '../../products_table.js' would be '../../products_table'.

If the problem persists please let me know.

Upvotes: 3

Related Questions