I am trying to import from typescript file, which is in node_modules. That file is not transpiled and uses typescript syntax:
user.ts:
export const getUserFromToken = (token: string) => {
return axios.get('/user', {
headers: { authorization: `Bearer ${token}` }
}).then(({ data }) => data)
}
I'm importing like this: import { getUserFromToken } from 'common-files/api/user', and common-files is a module registered in package.json.
When trying to compile, I get:
../commons/api/user.ts
Module parse failed: C:\Users\xxxx\Desktop\xxxx\commons\api\user.ts
Unexpected token (9:38)
You may need an appropriate loader to handle this file type.
| export const getUserFromToken = (token: string) => {
| return axios.get('/user', {
| headers: { authorization: `Bearer ${token}` }
Which leads, me to believe, that it's not compiling the ts file, because when I remove string type, it becomes a valid es6 file, and it starts correctly.
In my tsconfig.json file I have:
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts"
]
I was thinking, maybe to exclude node_modules, except that package common-files, but don't know how to do that. Is there a good way to achieve what I want at all?