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

Version 1.10.1 breaks absolute paths in typescript #2068

Closed
iRoachie opened this issue Sep 27, 2018 · 16 comments
Closed

Version 1.10.1 breaks absolute paths in typescript #2068

iRoachie opened this issue Sep 27, 2018 · 16 comments
Labels

Comments

@iRoachie
Copy link

iRoachie commented Sep 27, 2018

🐛 bug report

When updating to version 1.10.0 of parcel-bundler from 1.9.7, absolute paths in typescript are no longer working.

🎛 Configuration (.babelrc, package.json, cli command)

// package.json
{
  "name": "register",
  "version": "1.0.0",
  "main": "src/index.js",
  "private": true,
  "license": "MIT",
  "scripts": {
    "start": "parcel public/index.html",
    "build": "parcel build public/index.html",
    "lint": "tslint -c tslint.json --project tsconfig.json 'src/**/*.ts?(x)'",
    "precommit": "lint-staged"
  },
  "devDependencies": {
    "@types/react": "^16.4.14",
    "@types/react-document-title": "^2.0.3",
    "@types/react-dom": "^16.0.7",
    "@types/react-router-dom": "^4.3.1",
    "husky": "^0.14.3",
    "lint-staged": "^7.2.2",
    "parcel-bundler": "^1.10.1",
    "parcel-plugin-typescript": "^1.0.0",
    "prettier": "^1.14.2",
    "tslint": "^5.11.0",
    "tslint-config-airbnb": "^5.11.0",
    "tslint-config-prettier": "^1.15.0",
    "tslint-react": "^3.6.0",
    "typescript": "^3.0.3"
  },
  "dependencies": {
    "antd": "^3.9.2",
    "date-fns": "^1.29.0",
    "firebase": "^5.5.0",
    "react": "^16.5.1",
    "react-document-title": "^2.0.3",
    "react-dom": "^16.5.1",
    "react-router-dom": "^4.3.1",
    "styled-components": "^3.4.6"
  },
  "lint-staged": {
    "*.{ts,tsx}": [
      "tslint -c tslint.json --project tsconfig.json 'src/**/*.ts?(x)'",
      "git add"
    ]
  }
}

// tsconfig.json
{
  "compilerOptions": {
    "module": "esnext",
    "target": "es5",
    "lib": ["es7", "dom", "esnext.asynciterable"],
    "sourceMap": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "baseUrl": "src", // This is what allows the absolute paths to work
    "paths": {
      "@styled": ["utils/styled"]
    },
    "types": ["node"]
  }
}

Directory structure

screen shot 2018-09-27 at 7 14 33 am

🤔 Expected Behavior

When running parcel index.html, it should resolve the absolute paths and run the app. Since my baseUrl is set to src in tsconfig.json, then it should resolve the path as src/config/firebase

😯 Current Behavior

Parcel displays an error in which it's unable to resolve the path.
register/src/index.tsx:5:7: Cannot resolve dependency 'config/firebase'

💁 Possible Solution

Not sure what changes occurred in the 1.10.0 release, but the app was working fine using 1.9.4.
Remove my absolute path and use a relative path.

🔦 Context

It affects me as i'm no longer able to build my app. Here's link to source code https://github.com/iRoachie/register

💻 Code Sample

// index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';

import 'config/firebase';

import Shell from './containers/Shell';

ReactDOM.render(<Shell />, document.getElementById('root'));

🌍 Your Environment

Software Version(s)
Parcel 1.10.1
Node 8.11.4
npm/Yarn yarn 1.9.4
Operating System mac os 10.14
@DeMoorJasper
Copy link
Member

DeMoorJasper commented Sep 27, 2018

Not sure what would cause this as TS hasn't changed for about half a year.

It might be because we upgraded to TS 3?

@iRoachie
Copy link
Author

Not sure, as you see in my package.json, I'm also using typescript 3^

@DeMoorJasper
Copy link
Member

Did it work previous to 1.10?

@iRoachie
Copy link
Author

Yea the project is currently on 1.9.7

@ThomasK33
Copy link

ThomasK33 commented Sep 27, 2018

Same happens to me when switching from 1.9.7 to 1.10.1.

Yet I have an "@" character prepended to the paths, hence I got a different error message:
Failed to install @src/[...]

I'd assume that the bundler tries to install the missing dependency via yarn, instead of resolving it with the specified paths in the tsconfig.json file.

@Penagwin
Copy link

Penagwin commented Oct 5, 2018

I'm also getting the issue. It occurs even if auto install dependencies is turned off.

I believe it has to do with a change to Resolver.js (which one I'm not sure) between 1.9.7 and 1.10.1.

This one maybe? a769fa7#diff-f90b0caefa8028ff5ec8f2f2c2e6e39dL150

I'll try version [email protected] and see if the issue occurs there tomorrow.

EDIT: No dice :(

@ThomasK33
Copy link

Hey @DeMoorJasper, any news on this issue?

@DeMoorJasper
Copy link
Member

@ThomasK33 Not sure, TS asset handling hasn't changed in 1.10, so it's not really easy to pinpoint it.

If anyone wants to dig into this, definitely feel free to do so.

@nnecec
Copy link

nnecec commented Oct 16, 2018

Maybe some problems happened between [email protected] and parcel-plugin-typescript ?

@harry-sm
Copy link

@nnecec I think so too.

@DeMoorJasper
Copy link
Member

DeMoorJasper commented Oct 18, 2018

@nnecec if this is truly a parcel-plugin-ts bug it’s probably a good idea to move it to that repo.

In that case this issue should also be closed

Sent with GitHawk

@ghost
Copy link

ghost commented Nov 14, 2018

I also think that could be a compatibility issue between parcel-plugin-typescript and [email protected].
Parcel doesn't know anything about baseUrl and paths. If it sees an absolute module path (without "./" or "../" , "/" would indicate absolute path relative to the project root for parcel, "~" would be the package root ), it goes through the normal node lookup and tries to find the package innode_modules (correct me if Im wrong).
The plugin claims to do the job:

Path mappings:
Rewriting your import on the fly accordingly to your paths and baseUrl compiler options.

, could be broken.

(also still looking for an optimal solution to use typescript mappings)

@devongovett
Copy link
Member

cc. @fathyb any idea?

@bernatfortet
Copy link

Any update?

@joseluisq
Copy link

fathyb/parcel-plugin-typescript#59 issue is freezed for long time.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Jan 17, 2020
@github-actions github-actions bot closed this as completed Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants