score:0

i was getting the same error. but seeing a solution mentioned above typescript requires import/export. i added only this line

import bgps from '../../resources/bgps.png';

then the error gone. so even if it's a file that requires no import then keep one unused image file. though it'll cause warning in console log

in the following day i also got same error! closed vs code, opened again and bang! it was okay again

score:0

i got this same error when i created a .ts file instead of .tsx. i got the error after deleting the errant .ts file. restarting my dev server resloved the issue.

score:0

i had the same issue. i had a file in which i had import and export statements. the issue was that file was never used. as soon as i imported something from that file, this error was gone. so, if you are making a file like a common button and you saved that file, make sure you used that button before looking at the output.

score:0

here is a sample code i have. tdlr, u can try to module.exports = {} at the bottom of the page.

const readline = require('readline')

const rl = readline.createinterface({
  input: process.stdin,
  output: process.stdout
})

const question = (question) => {
  return new promise((resolve, reject) => {
    rl.question(question, (answer) => {
      resolve(answer)
    })
  })
}

const main = async () => {
  const username = await question('please enter a username: ');
  const password = await question('please enter a password: ');
  const email = await question('please enter an email:');
  console.log("result: ", {
      "username" : username,
      "password" : password
  });
  rl.close()
}

main()

module.exports = {}

i tried to use export {} but it did not work for me partly because i was trying to execute this file using node. so if u are executing the file using node, then use module.exports as shown above.

i would prefer to use set "isolatedmodules": false in tsconfig.json but because i need to run this separately alongside a next.js project this approach have worked for me.

the command to run to execute the file

node file_name_here.ts

score:1

be sure that anything you are importing is being exported from that path.

if it specific to the randomcolor import, make sure you also add the types for that package by installing @types/randomcolor

npm

npm i @types/randomcolor

yarn

yarn add @types/randomcolor

score:4

there is no export in the file!

for example you can add export default {} to fixed!

score:4

deleting any unused .tsx file should do the job.

score:5

i got the same error too. the reason why this is happening is that the react component you have created is not being used. so you can call the component, and you are good to go.

score:18

the problem is that in typescript by default, every file without importor export is a legacy scrip file.

as such files are not modules they are merged in the global namespace.

to change this behavior

a) add any import or export in the file, eg: export {}

b) set "isolatedmodules": false in tsconfig.json

note: nextjs will reset the value to true in every build, because for nextjs, "isolatedmodules": true is a requirement

score:29

may get this error with an unused .tsor .tsx file. i had empty .ts file i wasn't using so just had to delete the unused file.

deleted the unused file /example/index.ts


Related Query

More Query from same tag