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

.parcelrc fails to extend @parcel/config-default - cannot find module #5603

Closed
alindsay55661 opened this issue Jan 6, 2021 · 15 comments
Closed

Comments

@alindsay55661
Copy link

🐛 bug report

I'm getting started with parcel in a brand new project with only a few files. I want to use tsc as the default Typescript compiler so I'm following instructions posted here: https://v2.parceljs.org/languages/typescript/#typescript's-tsc

Once I added the .pacelrc parcel no longer complies. It now fails with the following error:

Error: Cannot find module '@parcel/config-default' from 'X:\projects\boomerang'
    at X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:116:35
    at processDirs (X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:269:39)
    at isdir (X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:276:32)
    at isDirectory (X:\projects\boomerang\boomerang-website\node_modules\@parcel\utils\lib\resolve.js:56:9) {
  code: 'MODULE_NOT_FOUND'
}

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

.parcelrc

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

.package.json

{
  "name": "boomerang-website",
  "version": "1.0.0",
  "scripts": {
    "prestart": "npm run clean",
    "start": "npx parcel ./src/*.html",
    "clean": "npx rimraf ./dist",
    "prebuild": "npm run clean",
    "build": "npx parcel build ./src/*.html",
    "predeploy": "npm run build",
    "deploy": "sls deploy -v"
  },
  "devDependencies": {
    "parcel": "^2.0.0-beta.1",
    "rimraf": "^3.0.2"
  },
  "dependencies": {
    "serverless-cloudfront-invalidate": "^1.5.0",
    "serverless-s3-sync": "^1.15.0"
  }
}

🤔 Expected Behavior

Should resolve @parcel/config-default, the package exists.

😯 Current Behavior

Error: Cannot find module '@parcel/config-default' from 'X:\projects\boomerang'
    at X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:116:35
    at processDirs (X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:269:39)
    at isdir (X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:276:32)
    at isDirectory (X:\projects\boomerang\boomerang-website\node_modules\@parcel\utils\lib\resolve.js:56:9) {
  code: 'MODULE_NOT_FOUND'
}

💁 Possible Solution

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel ^2.0.0-beta.1
Node v14.15.1
npm/Yarn npm@6.14.8
Operating System Windows 10
@mischnic
Copy link
Member

mischnic commented Jan 6, 2021

You should install @parcel/config-default and @parcel/transformer-typescript-tsc as dependencies

@alindsay55661
Copy link
Author

You should install @parcel/config-default and @parcel/transformer-typescript-tsc as dependencies

Apologies, I actually had done that. I removed them as part of a test and forgot to re-add them when opening this ticket. I can confirm that everything still fails with the following package.json:

{
  "name": "boomerang-website",
  "version": "1.0.0",
  "scripts": {
    "prestart": "npm run clean",
    "start": "npx parcel ./src/*.html",
    "clean": "npx rimraf ./dist",
    "prebuild": "npm run clean",
    "build": "npx parcel build ./src/*.html",
    "predeploy": "npm run build",
    "deploy": "sls deploy -v"
  },
  "devDependencies": {
    "@parcel/config-default": "^2.0.0-alpha.3",
    "@parcel/transformer-typescript-tsc": "^2.0.0-alpha.3",
    "parcel": "^2.0.0-beta.1",
    "rimraf": "^3.0.2"
  },
  "dependencies": {
    "serverless-cloudfront-invalidate": "^1.5.0",
    "serverless-s3-sync": "^1.15.0"
  }
}

npm start

Error: Cannot find module '@parcel/config-default' from 'X:\projects\boomerang'
    at X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:116:35
    at processDirs (X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:269:39)
    at isdir (X:\projects\boomerang\boomerang-website\node_modules\resolve\lib\async.js:276:32)
    at isDirectory (X:\projects\boomerang\boomerang-website\node_modules\@parcel\utils\lib\resolve.js:56:9) {
  code: 'MODULE_NOT_FOUND'
}

@mischnic
Copy link
Member

mischnic commented Jan 6, 2021

You can try using the nightly version (npm i -D parcel @parcel/transformer-typescript-tsc@nightly @parcel/config-default@nightly)? Otherwise please create a github repo to reproduce this.

@alindsay55661
Copy link
Author

I created a new repo for testing.

Installing as you suggest above gives me parcel@1.12.4 along with lots of npm warnings:

npm WARN @parcel/config-default@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/optimizer-terser@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/packager-js@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/transformer-babel@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is instalnpm WARN @parcel/transformer-coffeescript@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/transformer-js@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/transformer-react-refresh-wrap@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/transformer-sass@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/fs@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/workers@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN @parcel/transformer-typescript-types@2.0.0-nightly.515 requires a peer of @parcel/core@^2.0.0-alpha.3.1 but none is installed. You must install peer dependencies yourself.

found 1 high severity vulnerability

It does get rid of the error but it doesn't look like parcel is picking up my tsconfig.json. I'm unable to confirm that tsc is being used, seems like it's not based on the generated code and that fact that I enabled the validator and that is doing nothing.

.parcelrc

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

If I install parcel@nightly I get a different error.

ℹ Server running at http://localhost:1234
× Build failed.
Error: EINVAL: invalid argument, mkdir 'C:UsersAlan Lindsayprojectsparcel-errordistX:projectsparcel-errorsrc'
Error: EINVAL: invalid argument, mkdir 'C:\Users\Alan Lindsay\projects\parcel-error\dist\X:\projects\parcel-error\src'
{
  "name": "parcel-error",
  "version": "1.0.0",
  "scripts": {
    "prestart": "npm run clean",
    "start": "npx parcel ./src/*.html",
    "clean": "npx rimraf ./dist"
  },
  "devDependencies": {
    "@parcel/config-default": "^2.0.0-nightly.515",
    "@parcel/transformer-typescript-tsc": "^2.0.0-nightly.515",
    "@parcel/validator-typescript": "^2.0.0-nightly.515",
    "parcel": "^2.0.0-nightly.513",
    "rimraf": "^3.0.2",
    "typescript": "^4.1.3"
  }
}

This suggests to me that the problem may be intermittent as it's not occurring in parcel 2 in the new repo. As I can't reproduce it in the new repo, should I open a new ticket for the EINVAL: invalid argument, mkdir error and attach the repository? I am still unable to build using tsc, though in this case it's failing on a different error.

@mischnic
Copy link
Member

mischnic commented Jan 6, 2021

Please share a complete runnable example where this error occurs. You don't need to create a new issue

If I install parcel@nightly I get a different error.

Sorry, I forgot one @nightly.

@ebrensi
Copy link

ebrensi commented Jan 15, 2021

I'm not sure if this is the same issue but I have been trying to move my JS application over to TypeScript and take advantage of type-checking. According to Parcel v2 documentation (https://v2.parceljs.org/languages/typescript/#type-checking) in order to get application-wide (multiple modules) type-checking via parcel I need a .parcelrc with

{
  "extends": "@parcel/config-default",
  "validators": {
    "*.{ts,tsx}": ["@parcel/validator-typescript"]
  }
}

and tsconfig.json

{
  "include": ["src/**/*"]
}

I was building without either of these before. So I created those files. The first problem I encountered was as @alindsay55661 mentioned,

Error: Cannot find module '@parcel/config-default'

So I tried manually importing. npm install -D @parcel/config-default
Now, when attempting a parcel watch I get

@parcel/core: Invalid Parcel Config
../../../../../NotDropbox/heatflask/node_modules/@parcel/config-default/index.json:3:2
  2 |   "bundler": "@parcel/bundler-default",
> 3 |   "transforms": {
>   |   ^^^^^^^^^^^^ Did you mean "transformers"?
  4 |     "types:*.{ts,tsx}": [
  5 |       "@parcel/transformer-typescript-types"

It looks like there is a typo in @parcel/config-default?

But aside from that, should it be necessary to explicitly import @parcel/config-default? If so, shouldn't that be in the documentation? I am willing to add it if that is the correct solution.

@ebrensi
Copy link

ebrensi commented Jan 15, 2021

ok I tried changing transforms to transformers in @parcel/config-default and now I get

  @parcel/namer-default: bundle.getHash is not a function
TypeError: bundle.getHash is not a function
    at Object.name (/home/efrem/NotDropbox/heatflask/node_modules/@parcel/namer-default/lib/DefaultNamer.js:59:28)
    at BundlerRunner.nameBundle (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/core/lib/
BundlerRunner.js:181:39)
    at /home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/core/lib/BundlerRunner.js:169:50
    at Array.map (<anonymous>)
    at BundlerRunner.nameBundles (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/core/lib
/BundlerRunner.js:169:31)
    at async BundlerRunner.bundle (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/core/li
b/BundlerRunner.js:134:5)
    at async Parcel.build (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/core/lib/Parcel
.js:370:25)
    at async Parcel.startNextBuild (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/core/l
ib/Parcel.js:272:21)
    at async PromiseQueue._runFn (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/utils/li
b/PromiseQueue.js:98:7)
    at async PromiseQueue._next (/home/efrem/NotDropbox/heatflask/node_modules/parcel/node_modules/@parcel/utils/lib
/PromiseQueue.js:85:5)

This is a rabbit hole I don't want to go down right now.

@mischnic
Copy link
Member

mischnic commented Jan 15, 2021

Make sure that parcel, @parcel/config-default and @parcel/validator-typescript are all on the same (or latest) nightly version.

But aside from that, should it be necessary to explicitly import @parcel/config-default? If so, shouldn't that be in the documentation? I am willing to add it if that is the correct solution.

Yes, for example Yarn PnP would throw an error if you don't list it in the dependencies. But I'm not quite sure how to put that into the docs without adding a note to every blue "example" block with a .parcelrc (or maybe that's fine?)

@mischnic
Copy link
Member

I still think all of these problems are related to having incompatible versions of some Parcel packages.

@loynoir
Copy link

loynoir commented Apr 16, 2021

@alindsay55661 I workaround with below.

$ cat .npmrc 
public-hoist-pattern[]=@parcel/*

My situation is pnpm being strict checking dependencies.

@loynoir
Copy link

loynoir commented Apr 16, 2021

Although might be another situation to mine: default packaging not match.

Manual install specified without channel, seems not match.

$ cd `mktemp -d`
$ mkdir a b c d e
$ env -C a yarn add @parcel/config-default
$ env -C b yarn add parcel
$ env -C c yarn add parcel @parcel/config-default
$ jq -r .version < a/node_modules/@parcel/config-default/package.json
2.0.0-alpha.3
$ jq -r .version < b/node_modules/parcel/package.json                
2.0.0-beta.2
$ jq -r .version < c/node_modules/@parcel/config-default/package.json
2.0.0-alpha.3
$ jq -r .version < c/node_modules/parcel/package.json   
2.0.0-beta.2

Manual install specified with channel, seems match.

$ env -C d yarn add parcel@next @parcel/config-default@next
$ jq -r .version < d/node_modules/@parcel/config-default/package.json
2.0.0-beta.2
$ jq -r .version < d/node_modules/parcel/package.json   
2.0.0-beta.2

If your pm is not strict, let parcel auto install, seems match.

$ env -C e yarn add parcel@next
$ jq -r .version < e/node_modules/@parcel/config-default/package.json
2.0.0-beta.2
$ jq -r .version < e/node_modules/parcel/package.json 
2.0.0-beta.2

@stoic-jsartin
Copy link

Is there a solution? Hitting this in 2023

@saveriocastellano
Copy link

hit also on 2024

@mischnic
Copy link
Member

  1. Add all packages you have specified in .parcelrc as dependencies of your project
  2. Make sure all @parcel/* packages have the same version.

@ankushchk
Copy link

I tried configuring the parcel config file to disable default babel transpilation:-
Error: @parcel/core: Failed to parse .parcelrc

created the .parcelrc file at the project root

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{js,mjs,jsx,cjs,ts,tsx}": [
      "@parcel/transformer-js",
      "@parcel/transformer-react-refresh-wrap"
    ]
  }
}

any fixes?

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

No branches or pull requests

7 participants