parcel-plugin-typescript icon indicating copy to clipboard operation
parcel-plugin-typescript copied to clipboard

parcel-plugin-typescript breaks asset file imports

Open dortamiguel opened this issue 7 years ago • 3 comments

🐛 bug report

When I try to load an asset inside typescript I get undefined instead of the route for the file.

import characterImage from '@client/assets/img/character.png'
console.log(characterImage) // undefined

The code above works in normal .js

🤔 Expected Behavior

Import should return the string for the url of the asset.

😯 Current Behavior

I get undefined when trying to import.

💁 Possible Solution

Maybe it can help but it looks like require works as expected

const characterImage = require('@client/assets/img/character.png')

console.log(characterImage) // /character.f3137b4d.png
Software Version(s)
{
    "parcel-bundler": "^1.9.0",
    "parcel-plugin-typescript": "^1.0.0",
    "typescript": "^2.9.2"
}

dortamiguel avatar Jun 16 '18 07:06 dortamiguel

What's the contents of your tsconfig.json?

fathyb avatar Jun 16 '18 23:06 fathyb

Like this

{
	"compilerOptions": {
		"strict": true,
		"alwaysStrict": true,
		"module": "commonjs",
		"moduleResolution": "node",
		"types": ["node", "jest", "pixi.js"],
		"newLine": "LF",
		"outDir": "lib",
		"jsx": "preserve",
		"target": "es2017",
		"lib": [
			"es2017",
			"dom"
		],
		"noUnusedLocals": true,
		"noUnusedParameters": true,
		"noImplicitAny": true,
		"noFallthroughCasesInSwitch": true,
		"experimentalDecorators": true,
		"baseUrl": "./src",
		"paths": {
			"@common/*": ["./common/*"],
			"@client/*": ["./client/*"],
			"@server/*": ["./server/*"]
		}
	},
	"include": [
		"src/common/**/*.ts",
		"src/client/**/*.ts"
	],
	"exclude": [
		".git",
		"node_modules"
	]
}

dortamiguel avatar Jun 17 '18 00:06 dortamiguel

The workaround of using require doesn't work for me because I get the following error:

Cannot find name 'require'.

dlee avatar Sep 16 '18 08:09 dlee