TypeError: Cannot read property 'startsWith' of undefined...
See original GitHub issueHello!
I embarked on the journey to upgrade to Encore v0.21.0. I followed instructions (at https://symfony.com/blog/encore-0-21-0-webpack-4-support-copy-files-support-webpackencorebundle) closely. Yet i get this error and i can not figure out the problem.
Actually, this is second project that i am updating to Encore v0.21.0 and the first one works without a hitch. I compared configurations and can not see what could be wrong.
I tried deleting node_modules and rerunning yarn install but the problem persists.
What may the source of the problem be? Please advise. Thank you!
package.json
{
"devDependencies": {
"@symfony/webpack-encore": "^0.21.0",
"node-sass": "^4.10.0",
"sass-loader": "^7.0.1"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production"
},
"dependencies": {
"bootstrap": "^4.1.3",
"cookieconsent": "^3.0.6",
"countdown": "^2.6.0",
"jquery": "3.3.1",
"linearicons": "^1.0.1",
"magnific-popup": "^1.1.0",
"moment": "^2.21.0",
"moment-countdown": "^0.0.3",
"popper.js": "^1.14.5"
}
}
webpack.config.js
// webpack.config.js
var Encore = require('@symfony/webpack-encore');
Encore
// directory where all compiled assets will be stored
.setOutputPath('public/build/')
// what's the public path to this directory (relative to your project's document root dir)
.setPublicPath('/build')
.copyFiles({
from: './assets/static',
// optional target path, relative to the output dir
to: 'static/[path][name].[ext]'
// only copy files matching this pattern
//pattern: /\.(png|jpg|jpeg)$/
})
// empty the outputPath dir before each build
.cleanupOutputBeforeBuild()
// will output as public/build/app.js
.addEntry('app', './assets/js/app.js')
.addEntry('gallery', './assets/js/gallery.js')
.addEntry('contact_us', './assets/js/contact_us.js')
// will output as public/build/global.css
.addStyleEntry('main', './assets/css/main.scss')
.addStyleEntry('admin', './assets/css/admin.scss')
// allow sass/scss files to be processed
.enableSassLoader(function(sassOptions) {},
{
resolveUrlLoader: false
}
)
// allow legacy applications to use $/jQuery as a global variable
.autoProvidejQuery()
.autoProvideVariables({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
moment: 'moment',
countdown: 'countdown',
moment_countdown: 'moment-countdown',
magnific_popup: 'magnific-popup',
cookieconsent: 'cookieconsent'
})
.enableSourceMaps(!Encore.isProduction())
// create hashed filenames (e.g. app.abc123.css)
.enableVersioning()
.splitEntryChunks()
.enableSingleRuntimeChunk()
;
// export the final configuration
module.exports = Encore.getWebpackConfig();
error in console (command prompt)
PS C:\DEV\project123> yarn run encore dev
yarn run v1.12.3
$ C:\DEV\project123\node_modules\.bin\encore dev
Running webpack ...
ERROR Failed to compile with 1 errors
TypeError: Cannot read property 'startsWith' of undefined
at isRelative (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\formatters\moduleNotFound.js:5:17)
at Array.from.map.module (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\formatters\moduleNotFound.js:64:15)
at Array.map (<anonymous>)
at groupModules (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\formatters\moduleNotFound.js:62:43)
at formatErrors (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\formatters\moduleNotFound.js:74:18)
at format (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\formatters\moduleNotFound.js:87:10)
at format (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\core\formatErrors.js:12:33)
at Array.map (<anonymous>)
at formatErrors (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\core\formatErrors.js:15:21)
at FriendlyErrorsWebpackPlugin.displayErrors (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\friendly-errors-plugin.js:110:5)
at doneFn (C:\DEV\project123\node_modules\friendly-errors-webpack-plugin\src\friendly-errors-plugin.js:51:14)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\DEV\project123\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (C:\DEV\project123\node_modules\tapable\lib\Hook.js:154:20)
at emitRecords.err (C:\DEV\project123\node_modules\webpack\lib\Compiler.js:257:22)
at Compiler.emitRecords (C:\DEV\project123\node_modules\webpack\lib\Compiler.js:371:39)
at emitAssets.err (C:\DEV\project123\node_modules\webpack\lib\Compiler.js:251:10)
at hooks.afterEmit.callAsync.err (C:\DEV\project123\node_modules\webpack\lib\Compiler.js:357:14)
at _err0 (eval at create (C:\DEV\project123\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:20:1)
at C:\DEV\project123\node_modules\assets-webpack-plugin\dist\index.js:148:9
at C:\DEV\project123\node_modules\assets-webpack-plugin\dist\lib\output\createQueuedWriter.js:16:7
at C:\DEV\project123\node_modules\assets-webpack-plugin\dist\lib\output\createOutputWriter.js:74:13
at C:\DEV\project123\node_modules\graceful-fs\graceful-fs.js:43:10
at FSReqWrap.oncomplete (fs.js:135:15)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS C:\DEV\project123>
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property 'startsWith' of undefined
Hi, im trying to connect to MongoAtlas run an app that uses mongodb (^4.3.1 ) in nodejs (version 10.19.0), Windows 7 & then...
Read more >Cannot read property 'startsWith' of undefined - discord bot ...
Every time I attempt to command the bot in my discord chat (!on) I get the error "TypeError: Cannot read property 'startsWith' of...
Read more >Cannot read property 'startsWith' of undefined - YouTube
Your browser can't play this video. ... Mongodb error solved - TypeError - Cannot read property 'startsWith' of undefined.
Read more >TypeError: Cannot read property 'startsWith' of undefined #324
I know there is a related error in #284, I decided to open a new issue as this hits us 100% of the...
Read more >Vue3 Cannot read property 'startsWith' of undefined - Laracasts
Vue3 Cannot read property 'startsWith' of undefined ; true · "scripts" · "dev" ; "npm run development" · "development" · "cross-env NODE_ENV=development node_modules/ ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Rikijs,
This is probably related to this issue in friendly-errors-webpack-plugin (used in Encore to format errors): https://github.com/geowarin/friendly-errors-webpack-plugin/issues/79
A PR was opened for it a while ago, maybe we could try to patch that on our side while we wait for it to be merged.
Anyway, from what I understand it’s probably related to an import that contains an invalid path… maybe you could try commenting some of your entrypoints or the
copyFiles()method (it triggers that bug if the path indicated in thefromoption doesn’t exist) to pinpoint where it is located.If you’re using npm
^6.9.0you can fix this by aliasing version required by encore to one that was forked and fixed.Either run:
or add this to your package.json:
This fork is used by
vue-cliso it should be kept updated.