Typescript: Can't import ts-files from npm symbolic link folder. "Need appropriate loader" error.
See original GitHub issueHi. I’m trying to reuse some scripts among client app (based on CRA) and server (NodeJS, Typescript, ts-node as a runner). So I desided to move them in separate repo and import as separate package.
package.json
of this package:
{
"name": "@app/package",
"main": "./src/index.ts",
"module": "./src",
"source": "./src",
"types": "./src",
...
}
It works fine in server app.
server tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"outDir": ".dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"/"
]
},
"typeRoots" : ["./server.d.ts"],
"types": [
"@types/node",
"@types/express",
"@types/dotenv"
]
},
"include": [
"./**/*"
]
}
But I can’t make it work in CRA. Compiling fails with “Need appropriate loader” error.
Failed to compile.
../package/src/index.ts 11:18
Module parse failed: Unexpected token (11:18)
You may need an appropriate loader to handle this file type.
| import { createGriderUtils, GriderUtils } from './utils';
|
> export const utils: GriderUtils = createGriderUtils();
|
| const builder: ShapeBuilder = new ShapeBuilder(utils);
clienttsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"jsx": "preserve",
"downlevelIteration": true,
"isolatedModules": true
},
"include": [
"src"
]
}
What am I doing wrong?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:17
- Comments:15
Top Results From Across the Web
Unable to compile TypeScript of symlinked package using ...
I'm using webpack with babel-loader in 'web'. When I symlink 'shared', it's unable to compile its TypeScript. This issue suggests using symlinks ...
Read more >Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >You may need an appropriate loader to handle this file type ...
I'm having a problem configuring Webpack for Typescript and React. After running the NPM script: webpack serves ./webpack/webpack.config.ts ...
Read more >npm-link
First, npm link in a package folder with no arguments will create a symlink in the global folder {prefix}/lib/node_modules/<package> that links to the ......
Read more >Module not found: Can't resolve 'X' error in React | bobbyhadz
Make sure the names of the folder and files in your project don't contain special characters, e.g. a hash # symbol, because your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Toub heres an example of what we use now typescript-monorepo-with-create-react-app. The best part is that we didn’t have to eject.
Issues so far is you cannot share
.css
nicely fromlib-packages
since you manually have to import it. We don’t mind it since we focus on codifying our styling with https://emotion.sh.I haven’t gotten it to work nicely with https://expo.io/ so it have its own process where I still have to symlink packages and use typescript to emit code that is consumed by
expo
.Hope you can find this helpful.
Any updates, workarounds are appreciated!