0

I've a typescript project I'm migrating from react-script to parcel.

However after running parcel, the project builds, but the url renders a 404 page not found html...

Here are the config files :

package.json :

{
  "name": "my-project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@blueprintjs/core": "^3.45.0",
    "@emotion/react": "^11.4.0",
    "@emotion/styled": "^11.3.0",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^16.9.3",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/react-router-dom": "^5.1.7",
    "axios": "^0.21.4",
    "cross-env": "^7.0.3",
    "dotenv": "^10.0.0",
    "pullstate": "^1.22.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "reselect": "^4.0.0",
    "spinners-react": "^1.0.4",
    "ts-loader": "^9.2.6",
    "typescript": "^4.4.3",
    "use-axios-client": "^2.0.0",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "cross-env NODE_ENV=local parcel ./src/index.tsx -p 3000",
    "build": "parcel build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "devDependencies": {
    "@babel/core": "latest",
    "@babel/preset-env": "^7.12.7",
    "@babel/preset-typescript": "latest",
    "@parcel/transformer-inline-string": "2.0.0-rc.0",
    "@parcel/transformer-svg-react": "^2.0.0-nightly.1739",
    "@parcel/config-default": "latest",
    "css-loader": "^6.3.0",
    "file-loader": "^6.2.0",
    "parcel": "^2.0.0-rc.0",
    "prettier": "2.3.1"
  }
}

tsconfig.json :

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "strict": true,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "module": "es6",
    "moduleResolution": "node",
    "target": "es5",
    "allowJs": true,
    "jsx": "react",
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "dist",
    "node_modules"
  ],
}

.parcelrc :

{
    "extends": "@parcel/config-default",
    "transformers": {
      "bundle-text:*": ["...", "@parcel/transformer-inline-string"],
      "jsx:*.svg": ["...", "@parcel/transformer-svg-react"]
    }
}

As I'm new to build tools - and parcel as well, I'm not sure what I did wrong here...

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26
Cromm
  • 328
  • 6
  • 25

1 Answers1

2

Your start script should target the .html file that you want to serve instead of .ts files directly. Parcel works a bit different from bundlers like webpack in that it can resolve dependencies from html directly.

So your start script would look like this:

cross-env NODE_ENV=local parcel ./src/index.html -p 3000

...and your index.html file would have a line like this:

<script type="module" src="index.tsx"></script>

See this example in the getting started docs

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26
  • I've also tried that, although it indeed fixes the 404 page not found issue, it renders a blank page and no source are present. I should have edit my question after trying that. I have no such blank page with react-scripts. Anyway, I'll accept your answer. – Cromm Oct 20 '21 at 09:27
  • There are several things that could cause that - is there any console output when you see the blank page? As a first step, I'd recommend following the [parcel + react getting started instructions](https://parceljs.org/recipes/react/#getting-started). If you can share a repro on github, I'm happy to take a look at that, too. – Andrew Stegmaier Oct 20 '21 at 13:57
  • Yes there is a repo, https://github.com/CrommVardek/polk-auction-ui/tree/parcel-migration . I would appreciate it if you could take a look. But as I spent too much time trying to use parcel, I'll probably stick to react-scripts for now until I have a functioning UI. However if you manage to found what is the cause, feel free to open a PR, or open an issue. – Cromm Oct 20 '21 at 14:32
  • 1
    I fixed a few layers of issues in [this pull request](https://github.com/CrommVardek/polk-auction-ui/pull/1) - details are there. Hope that helps! – Andrew Stegmaier Oct 20 '21 at 15:20