Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolver not works, is it anything wrong? #3

Closed
qtisan opened this issue Aug 28, 2021 · 8 comments
Closed

resolver not works, is it anything wrong? #3

qtisan opened this issue Aug 28, 2021 · 8 comments

Comments

@qtisan
Copy link

qtisan commented Aug 28, 2021

I create a simple example for this resolver, but not works, maybe something wrong with version of packages?

it is the details below, need help!

OS: macOS 11.5.2
node: v14.17.0

gist: https://gist.github.com/qtisan/78797db3babf2ebaf01578a6797891c9

Error:

yarn run v1.22.10
$ parcel build
🚨 Build failed.

@parcel/core: Failed to resolve '@lib' from '....../parcel-module-alias/src/web/app.tsx'

  ....../parcel-module-alias/src/web/app.tsx:3:26
    2 | import ReactDom from 'react-dom';
  > 3 |
  >   | ^
    4 | import { sayHello } from '@lib';
    5 |

@parcel/resolver-default: External dependency "@lib" is not declared in package.json.

....../parcel-module-alias/package.json:22:3
    21 |   },
  > 22 |   "dependencies": {
  >    |   ^^^^^^^^^^^^^^
    23 |     "react": "^17.0.2",
    24 |     "react-dom": "^17.0.2"

  💡 Add "@lib" as a dependency.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
....../parcel-module-alias (master *)$ yarn build-tsc
yarn run v1.22.10
$ tsc
✨  Done in 1.37s.

Files:
image

src/lib/index.ts

export function sayHello(name: string): string {
  return `Hello, ${name}`;
}

src/web/app.tsx

import React from 'react';
import ReactDom from 'react-dom';

import { sayHello } from '@lib';

const App = () => <h1>{sayHello('Jack')}</h1>;

ReactDom.render(<App />, document.getElementById('app'));

src/web/index.html

<!DOCTYPE html>
<div id="app"></div>
<script src="./app.tsx" type="module"></script>

.parcelrc

{
  "extends": "@parcel/config-default",
  "resolvers": ["@parcel/resolver-default", "parcel-resolver-tspaths"],
  "transformers": {
    "*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
  },
  "validators": {
    "*.{ts,tsx}": ["@parcel/validator-typescript"]
  },
}

package.json

{
  "name": "parcel-module-alias",
  "version": "0.0.1",
  "source": "src/web/index.html",
  "license": "ISC",
  "scripts": {
    "start": "parcel src/web/index.html",
    "build-tsc": "tsc",
    "build": "parcel build"
  },
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@parcel/transformer-typescript-tsc": "^2.0.0-rc.0",
    "@parcel/ts-utils": "^2.0.0-rc.0",
    "@parcel/validator-typescript": "^2.0.0-rc.0",
    "@types/react": "^17.0.19",
    "@types/react-dom": "^17.0.9",
    "parcel": "^2.0.0-rc.0",
    "parcel-resolver-tspaths": "^0.0.5",
    "typescript": "4.3.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "allowJs": false,
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "alwaysStrict": true,
    "baseUrl": ".",
    "declaration": true,
    "declarationMap": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "lib": ["esnext", "DOM"],
    "module": "CommonJS",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "outDir": "./dist",
    "paths": {
      "@lib": ["./src/lib"]
    },
    "preserveConstEnums": true,
    "pretty": true,
    "removeComments": false,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "suppressImplicitAnyIndexErrors": true,
    "target": "ES5"
  },
  "include": ["src"],
  "exclude": ["node_modules/"]
}
@qtisan
Copy link
Author

qtisan commented Aug 28, 2021

I try parcel build --log-level verbose, no more printed.

yarn run v1.22.10
$ parcel build --log-level verbose --detailed-report 10
🚨 Build failed.

@parcel/core: Failed to resolve '@lib' from '....../src/web/app.tsx'

  ....../src/web/app.tsx:3:26
    2 | import ReactDom from 'react-dom';
  > 3 |
  >   | ^
    4 | import { sayHello } from '@lib';
    5 |
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@Poky85
Copy link

Poky85 commented Oct 2, 2021

@qtisan I think it would be better if you could create repo with reproducible example.

@zachbryant
Copy link
Owner

I'm curious, does your intellisense autocomplete @lib paths? That would tell me if your config is correct. Also is this issue still happening for you?

@zachbryant
Copy link
Owner

There's a new version available. Let me know if you're still having issues on it

@valepu
Copy link

valepu commented Apr 29, 2022

Hi,
I'm having the same issue with paths not being resolved (I have installed the latest version 0.0.7).
My situation is very similar to the one described in the post but let me know if there's anything I can add to help investigating

VS code can autocomplete my imports (and if I ctrl+click on them it sends me to the correct file)

EDIT: While investigating further on the issue I found this parcel-bundler/parcel#4936 and I can confirm this is the kind of imports I have in my project

@zachbryant
Copy link
Owner

Looks like the issue here might be related to #5 , in which non-src baseUrls weren't resolving. I'll look into this, but do let me know how 0.0.8 fares for you as well.

@zachbryant
Copy link
Owner

One potential issue is that you're including your baseUrl in the path alias. If it were anything other than the current folder ., this would not work. However I have identified the issue and will be publishing the fix soon.

@zachbryant
Copy link
Owner

Should be fixed in 0.0.9 now, tested with a reconstructed environment based on the pasted code. Go ahead and reopen this if the update doesn't fix it.

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

No branches or pull requests

4 participants