laravel-mix-react-typescript-extension icon indicating copy to clipboard operation
laravel-mix-react-typescript-extension copied to clipboard

Compile Error

Open keidarcy opened this issue 5 years ago • 4 comments

I'm using this package to compile react with ts, working great at the local environment. But when I up to a server, it can't compile. Got this error.

Run npm run prod

> @ prod /home/runner/work/rekishi/rekishi
> npm run production

> @ production /home/runner/work/rekishi/rekishi
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

 ERROR  Failed to compile with 1 errors6:12:41 AM
TypeError: Cannot read property 'startsWith' of undefined
    at isRelative (/home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:5:17)
    at /home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:64:15
    at Array.map (<anonymous>)
    at groupModules (/home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:62:43)
    at formatErrors (/home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:74:18)
    at format (/home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:87:10)
    at format (/home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/core/formatErrors.js:12:33)
    at Array.map (<anonymous>)

Do you have any ideas?

keidarcy avatar Aug 21 '20 06:08 keidarcy

Huh, I have no idea. But to help you out, I am gonna try to guess. This seems to be the culprit: TypeError: Cannot read property 'startsWith' of undefined. What version of node do you have installed on the server?

raicem avatar Aug 21 '20 07:08 raicem

@raicem Thanks for your kindness 😭

I'm using Github Action, OS is ubuntu-latest.

Run node -v 
  node -v 
  npm -v
  npm run prod
  shell: /bin/bash -e {0}
v12.18.3
6.14.7

> @ prod /home/runner/work/rekishi/rekishi
> npm run production


> @ production /home/runner/work/rekishi/rekishi
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js --scripts-prepend-node-path

 ERROR  Failed to compile with 1 errors8:12:55 AM
TypeError: Cannot read property 'startsWith' of undefined
    at isRelative (/home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:5:17)
    at /home/runner/work/rekishi/rekishi/node_modules/friendly-errors-webpack-plugin/src/formatters/moduleNotFound.js:64:15

Here is node(v12.18.3) and npm(6.14.7) version.

My local version is node(v12.16.1), npm(6.14.2).

TypeError: Cannot read property 'startsWith' of undefined seems like a wrong import problem, but I don't know how can it compile in the local environment.

keidarcy avatar Aug 21 '20 08:08 keidarcy

Here is how I config webpack.mix.js.

const path = require('path')
let mix = require('laravel-mix')

require('laravel-mix-react-typescript-extension')

mix.reactTypeScript(
  path.resolve(__dirname, 'resources/ts/xx.tsx'),
  path.resolve(__dirname, 'public/js/xx.min.js')
)

mix.disableSuccessNotifications().version()

And the output of tsc is nothing.

keidarcy avatar Aug 21 '20 08:08 keidarcy

I was hoping to see drastic version difference of node :smile: I was thinking startsWith is relatively new and may not be supported on all node versions.

I now also think that I have interpreted the error message wrong. There is nothing wrong with startWith but on which object it is used. Looks like that object is undefined in prod mode. Why would a variable goes undefined in prod and not dev is beyond me. Some optimizations going wrong? I don't even know if that is related to the code you have written or any other library code.

Sorry, that's all I can think of.

raicem avatar Aug 21 '20 09:08 raicem