parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.47k stars 2.27k forks source link

Parcel build throws Unknown error #1752

Closed Jancat closed 6 years ago

Jancat commented 6 years ago

🐛 bug report

I'm building a vue application with typescript. There is normal when running parcel index.html, but error was thrown in parcel build index.html

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

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "jsx": "preserve",
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitReturns": true,
    // "sourceMap": true,
    // "strict": true,
    "target": "es5",
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext"]
  },
  "parcelTsPluginOptions": {
    // If true type-checking is disabled
    "transpileOnly": false
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
  "exclude": ["node_modules"]
}

package.json

{
  "name": "finchat-h5-pages",
  "version": "0.1.0",
  "description": "FinChat H5 pages repository.",
  "main": "index.js",
  "private": true,
  "scripts": {
    "lint": "tslint -c tslint.yaml 'src/**/*.ts'; wotan '**/*.vue'",
    "lint:fix": "tslint -c tslint.yaml --fix 'src/**/*.ts'; wotan --fix '**/*.vue'",
    "clean": "rm -rf .cache && rm -rf dist",
    "prestart": "yarn clean",
    "start": "parcel public/index.html",
    "dev": "yarn clean && NODE_ENV=production parcel public/index.html",
    "staging": "yarn clean && NODE_ENV=staging parcel public/index.html",
    "prod": "yarn clean && NODE_ENV=production parcel public/index.html",
    "build": "parcel build public/index.html",
    "prepush": "yarn lint",
    "svg": "vsvg -s ./src/assets/icons -t ./src/components/icons --ext ts --es6",
    "mock": "json-server --watch mock/db.json dist/index.html --static ./dist --port 3004 --routes mock/routes.json"
  },
  "dependencies": {
    "babel-polyfill": "^6.26.0",
    "lodash": "^4.17.10",
    "vant": "^1.1.12",
    "vue": "^2.5.16",
    "vue-class-component": "^6.2.0",
    "vue-head": "^2.0.12",
    "vue-hot-reload-api": "^2.3.0",
    "vue-property-decorator": "^7.0.0",
    "vue-router": "^3.0.1",
    "whatwg-fetch": "^2.0.4"
  },
  "devDependencies": {
    "@fimbul/valtyr": "^0.11.0",
    "@fimbul/ve": "^0.11.0",
    "@fimbul/wotan": "^0.11.0",
    "@types/config": "^0.0.34",
    "@types/lodash": "^4.14.111",
    "@types/node": "^10.5.2",r
    "@vue/component-compiler-utils": "^2.1.0",
    "autoprefixer": "^8.6.5",
    "husky": "^0.14.3",
    "json-server": "^0.14.0",
    "node-sass": "^4.9.2",
    "parcel-bundler": "^1.9.4",
    "parcel-plugin-typescript": "^1.0.0",
    "postcss-modules": "^1.1.0",
    "postcss-px-to-viewport": "^0.0.3",
    "prettier": "^1.13.7",
    "ts-import-plugin": "^1.5.4",
    "tslint": "^5.10.0",
    "tslint-config-prettier": "^1.13.0",
    "tslint-eslint-rules": "^5.3.1",
    "tslint-plugin-prettier": "^1.3.0",
    "typescript": "^2.9.2",
    "vue-svgicon": "^3.0.2",
    "vue-template-compiler": "^2.5.16"
  },
  "browserslist": [
    "Android >= 5.0",
    "iOS >= 9"
  ]
}

🤔 Expected Behavior

parcel build index.html successfully output dist directory

😯 Current Behavior

When execute NODE_ENV=production parcel build index.html and parcel build index.html, the error was thrown:

Unknown error
    at Object.jsonToError (/xxx/node_modules/parcel-bundler/src/workerfarm/errorUtils.js:15:15)
    at Worker.receive (/xxx/node_modules/parcel-bundler/src/workerfarm/Worker.js:150:32)
    at ChildProcess.emit (events.js:182:13)
    at emit (internal/child_process.js:811:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

parcel build index.html works normally. So is the NODE_ENV=production makes the error?

I debug the

https://github.com/parcel-bundler/parcel/blob/2e1ffc65c793a9d391a483ba43dea7962880f40c/src/workerfarm/Worker.js#L142

and log the call error info:

call { method: 'run',
  args:
   [ '/xxx/src/views/product/ProductList.vue',
     false ],
  retries: 0,
  resolve: [Function],
  reject: [Function] }

💁 Possible Solution

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 1.9.7
Node 10.5.0
npm/Yarn Yarn
Operating System Mac OS X
DeMoorJasper commented 6 years ago

Is this error reproducable? Not sure why this is happening? Could you make a reproducable example repository?

Unknown error is a bit vague to resolve into an actual cause

Jancat commented 6 years ago

The demo repository is here https://github.com/Jancat/parcel-vue-ts-demo.

Because of the issue of parcel build, I had to import vue-cli to build the dist.

andrewbanchich commented 6 years ago

@DeMoorJasper I'm getting the same error and found this when trying to figure out why.

Also, I'm not using TypeScript at all.

DeMoorJasper commented 6 years ago

@andrewbanchich Unknown error can pretty much be everything but I'll look into it when I find the time

DeMoorJasper commented 6 years ago

This is a fairly strange error, for some reason it throws a string instead of an error somewhere. This is the real error message:

Error: Error: Error: Cannot find source file "/Users/demoor/Documents/parcel-vue-ts-demo/src/views/product/ProductList.vue"
    at TypeScriptCompiler.compile (/Users/demoor/Documents/parcel-vue-ts-demo/node_modules/parcel-plugin-typescript/build/backend/compiler/tsc.js:24:19)
    at Object.<anonymous> (/Users/demoor/Documents/parcel-vue-ts-demo/node_modules/parcel-plugin-typescript/build/backend/worker/launcher.js:28:29)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/demoor/Documents/parcel-vue-ts-demo/node_modules/tslib/tslib.js:104:62)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at TypeScriptWorker.<anonymous> (/Users/demoor/Documents/parcel-vue-ts-demo/node_modules/parcel-plugin-typescript/build/backend/ipc/worker/index.js:27:19)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/demoor/Documents/parcel-vue-ts-demo/node_modules/tslib/tslib.js:104:62)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at IncomingMessage.res.setEncoding.on (/Users/demoor/Documents/parcel-vue-ts-demo/node_modules/parcel-plugin-typescript/build/backend/ipc/client.js:31:32)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
andrewbanchich commented 6 years ago

How can I see the "real" error message?

I only get this when building Vue as well, but when I serve it for dev it is totally fine. I just finished porting all the code from Webpack to Parcel, so it would be helpful if I had a way to find out where this error is actually originating.

andrewbanchich commented 6 years ago

I got it working. I think it was related to #1124 , since I eventually got it to display a real error message.

DeMoorJasper commented 6 years ago

@andrewbanchich I opened a PR that fixes this issue, like mentioned above. #1761

Jancat commented 6 years ago

@DeMoorJasper Could you tell me how to fix the error that Cannot find source file? I had imported parcel-plugin-typescript to configure baseUrl and paths in tsconfig.json.

And it works fine on parcel public/index.html except throw the error UnhandledPromiseRejectionWarning: Error: Error: Error: Could not find file: xxx .

DeMoorJasper commented 6 years ago

Probably best to report it to parcel-plugin-ts

Sent with GitHawk