Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

ES6 import for svg not working but require works #32

Closed
jeremistadler opened this issue Mar 23, 2017 · 3 comments
Closed

ES6 import for svg not working but require works #32

jeremistadler opened this issue Mar 23, 2017 · 3 comments

Comments

@jeremistadler
Copy link
Contributor

Description

I'm trying to import svg images with the following code:

import food from './food.svg';

Expected behavior

It works in create-create-app

Actual behavior

(8,18): error TS2307: Cannot find module './food.svg'.

Environment

os: OSX
node: 7.7.1
yarn: 0.21.3
react-scripts-ts: 1.1.8

@jeremistadler jeremistadler changed the title Svg import not working ES6 import for svg not working but require works Mar 23, 2017
@wmonk
Copy link
Owner

wmonk commented Mar 28, 2017

This is a Typescript this - please see this thread microsoft/TypeScript#6615. Essentially you need to use require as imports something as an any and means TS won't try and type it.

@wmonk wmonk closed this as completed Mar 28, 2017
@houfeng0923
Copy link

https://webpack.bootcss.com/guides/webpack-and-typescript/#importing-non-code-assets

@JamesTheHacker
Copy link

Exactly the same issue. require works but remember to install the types:

yarn add @types/node --save-dev

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants