question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: Can't import ts-files from npm symbolic link folder. "Need appropriate loader" error.

See original GitHub issue

Hi. 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:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:15

github_iconTop GitHub Comments

2reactions
christiantaklecommented, Jul 27, 2019

@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 from lib-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.

2reactions
Soleksandrcommented, May 28, 2019

Any updates, workarounds are appreciated!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found