Skip to content

Could not find file .png #223

Closed
Closed
@oojacoboo

Description

@oojacoboo

Getting the following error when running ts-node. I haven't been able to resolve an issue surrounding asset requires with ts-node. However, it seems to be working properly with tsc and the proper definition types.

Error: Could not find file: '/valid/path/to/actual/file/image.png'. at getValidSourceFile (~/node_modules/typescript/lib/typescript.js:73826:23)

I thought it might be a typescript version issue at first, but I've confirmed that 2.1.0-dev is being used.

When enabling the fast prop for the register config, I then get hundreds of the following errors:

/valid/path/to/actual/file/image.png (38,64): Invalid character. (1127)
/valid/path/to/actual/file/image.png (38,64): Argument expression expected. (1135)
/valid/path/to/actual/file/image.png (38,64): Unterminated string literal. (1002)

Basically it seems it's trying to interpret the file as .js. I've tried defining the gif module as well like the following to no avail.

src/@types/images/index.d.ts

declare module '*.png' {
  const png: any;
  export default png;
}

The only thing I can do to get it working is override the require.extensions assignment for each extension and silence it. Unfortunately, this is a pretty big hack IMO.

I'm not really sure what else to dig into here. Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionSupport requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions