Vue-cli run build TypeError 'name' Undefined - vue-cli

I just started to use vue-cli and I got stock with a problem.
Following the Docs instructions:
I installed vue/cli npm install -g #vue/cli (version 3.11.0).
I created a project vue create test (default config) and cd into the folder.
But when I tried to build the project npm run build, I got this error.
TypeError: Cannot read property 'name' of undefined
at entrypoint.getFiles.reduce (C:\Users\MyUser\test\node_modules\webpack\lib\performance\SizeLimitsPlugin.js:43:25)
at Array.reduce (<anonymous>)
at getEntrypointSize (C:\Users\MyUser\test\node_modules\webpack\lib\performance\SizeLimitsPlugin.js:40:27)
at compiler.hooks.afterEmit.tap.compilation (C:\Users\MyUser\test\node_modules\webpack\lib\performance\SizeLimitsPlugin.js:75:18)
at _next0 (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:10:1)
at _err0 (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:24:1)
at callback (C:\Users\MyUser\test\node_modules\copy-webpack-plugin\dist\index.js:126:17)
at afterEmit (C:\Users\MyUser\test\node_modules\copy-webpack-plugin\dist\index.js:220:13)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:20:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\MyUser\test\node_modules\tapable\lib\Hook.js:154:20)
at asyncLib.forEachLimit.err (C:\Users\MyUser\test\node_modules\webpack\lib\Compiler.js:482:27)
at C:\Users\MyUser\test\node_modules\neo-async\async.js:2818:7
at done (C:\Users\MyUser\test\node_modules\neo-async\async.js:3522:9)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\MyUser\test\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at outputFileSystem.writeFile.err (C:\Users\MyUser\test\node_modules\webpack\lib\Compiler.js:464:33)
at C:\Users\MyUser\test\node_modules\graceful-fs\graceful-fs.js:57:14
I tried it in different folders of my PC in case some file were having conflict but with no luck.
Any idea how can I solve this?

Update: This was a bug in Webpack 4.40.0 and 4.40.1 and should now be fixed.
Line 43 of Webpack's SizeLimitsPlugin.js can be seen here:
https://github.com/webpack/webpack/commit/758269e81456c946a96b521ee936dbec99d07132#diff-cf9a43cf0e0fef12e89091cd183c607dR43
As suggested by the error message it is trying to access asset.name.
It would appear that this line got changed in the last few days and the change made it into the 4.40.0 release. I don't have enough familiarity with that code to say for sure whether it is to blame for the error but it is suspicious.
It seems that other Vue users have run into the same problem:
https://github.com/vuejs/vue-cli/issues/4572
Several workarounds are suggested there. e.g.:
Create a file called vue.config.js alongside your package.json and add the following code to that file:
module.exports = {
css: {
sourceMap: true
}
}
Alternatively you can use:
module.exports = {
productionSourceMap: false
}
or:
module.exports = {
configureWebpack: {
devtool: "eval-source-map"
}
}
For more information on what these do see https://cli.vuejs.org/config/#vue-config-js
The settings sourceMap: true and productionSourceMap: false can also be set via the UI if you run vue ui and go into the configuration for your project.

Related

Webpack - Reading from "node:XXX" is not handled by plugins

I've got a typescript project that I'm building using Webpack. I'm fairly new to web development in general, so forgive me if my terminology isn't always correct.
I'm trying to use the following npm package: https://www.npmjs.com/package/nodewikiaapi
Here are the steps that I followed (I've also done much troubleshooting an tried many webpack configuration changes with no luck):
install the package via npm install --save-dev nodewikiaapi
include it in my TS file like so: import WikiaAPI from 'nodewikiaapi'
try to compile, and I get a few instances of the the following error (or similar, with different variations on "node:XXX"):
Module build failed: UnhandledSchemeError: Reading from "node:zlib" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\webpack\lib\NormalModule.js:832:25
at Hook.eval [as callAsync] (eval at create (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at Object.processResource (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\webpack\lib\NormalModule.js:829:8)
at processResource (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\loader-runner\lib\LoaderRunner.js:220:11)
at iteratePitchingLoaders (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\loader-runner\lib\LoaderRunner.js:171:10)
at runLoaders (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\loader-runner\lib\LoaderRunner.js:398:2)
at NormalModule._doBuild (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\webpack\lib\NormalModule.js:819:3)
at NormalModule.build (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\webpack\lib\NormalModule.js:963:15)
at C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\webpack\lib\Compilation.js:1371:12
at NormalModule.needBuild (C:\Users\carso\Documents\Programming\TolkienExplorer_Web\node_modules\webpack\lib\NormalModule.js:1253:32)
# ./node_modules/node-fetch/src/index.js 11:0-29 297:11-28 298:17-34 303:22-39 325:24-42 331:24-45 354:22-49
# ./node_modules/nodewikiaapi/src/main.js 3:0-30 201:29-34
# ./static/src/index.ts 4:0-36 39:24-32
I've tried many things, including installing the node-polyfill-webpack-plugin and then including the following in my webpack.config.js:
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = {
// Other rules...
plugins: [
new NodePolyfillPlugin()
]
};
It's very possible that I've been missing some key detail though.
Do I need to change my import statement? import WikiaAPI from 'nodewikiaapi'
Do I need to add some sort external to my webpack config?
Do I need to include the node plugin in webpack differently?
Something else altogether?

Laravel Mix: ValidationError: CSS Loader has been initialized using an options object that does not match the API schema

I recently tried to run npm run dev and also npm run watch, but I got an error after 80% got compiled. I tried googling it but didn't find the solution to it. Below is the error which I get in my console.
ERROR in ./resources/sass/frontend/app.scss Module build failed (from
./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from
./node_modules/css-loader/dist/cjs.js): ValidationError: Invalid
options object. CSS Loader has been initialized using an options
object that does not match the AP I schema.
options.url should be one of these: boolean | object { filter? } -> Allows to enables/disables url()/image-set() functions handling. -> Read more at
https://github.com/webpack-contrib/css-loader#url Details:
options.url should be a boolean.
options.url should be an object:
object { filter? }
at validate (E:\Web Projects\project\node_modules\webpack\node_modules\schema-utils\dist\validate.js:105:11)
at Object.getOptions (E:\Web Projects\project\node_modules\webpack\lib\NormalModule.js:527:19)
at Object.loader (E:\Web Projects\project\node_modules\css-loader\dist\index.js:31:27)
at processResult (E:\Web Projects\project\node_modules\webpack\lib\NormalModule.js:701:19)
at E:\Web Projects\project\node_modules\webpack\lib\NormalModule.js:807:5
at E:\Web Projects\project\node_modules\loader-runner\lib\LoaderRunner.js:399:11
at E:\Web Projects\project\node_modules\loader-runner\lib\LoaderRunner.js:251:18
webpack.mix.js
const mix = require('laravel-mix');
mix.setPublicPath('public')
.setResourceRoot('../')
.vue()
.sass('resources/sass/frontend/app.scss', 'css/frontend.css')
.sass('resources/sass/backend/app.scss', 'css/backend.css')
.js('resources/js/frontend/app.js', 'js/frontend.js')
.js([
'resources/js/backend/before.js',
'resources/js/backend/app.js',
'resources/js/backend/after.js'
], 'js/backend.js')
.js('resources/js/global.js', 'js/global.js')
.js('resources/js/Banners/banner.js', 'js/banner.js')
.extract([
// Extract packages from node_modules to vendor.js
'alpinejs',
'jquery',
'bootstrap',
'popper.js',
'axios',
'sweetalert2',
'lodash'
])
.sourceMaps();
if (mix.inProduction()) {
mix.version();
} else {
// Uses inline source-maps on development
mix.webpackConfig({
loader: 'url-loader',
devtool: 'inline-source-map'
});
}
Both Frontend.scss & Backend.scss are not getting compiled or mixed and throws up an error given above. When I tried to comment it, it ran properly as expected, but without commenting it, it doesn't. I don't know where I am going wrong here. I also tried to run npm rebuild node-sass and then again tried to run npm run prod, npm run dev & npm run watch, but none worked.
As a workaround, downgrade your css-loader package to a 5.x version.
npm install css-loader#5.2.7 --save-dev

AWS Lambda: module initialization error: Error at Error (native) at Object.fs.openSync (fs.js:641:18)

I have an AWS DynammoDB lambda which triggers by a DynamoDB stream. All implementation has been done in JS with ClaudiJS. When the lambda is deployed with the claudia create command there is no issue.
The problem is when the same function is deployed with GoCD pipeline using a dockerized build server following error occurs when the lambda function gets called.
module initialization error: Error
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at Object.Module._extensions..js (module.js:578:20)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
Now I have spent over 10 hours and I have no idea of resolving this issue. Can someone please help me?
Lambda uses Node 6.10 and I use babel to transpile to node 6.10 .
Tried withnode:boron and ubuntu:16.04 images as builder images for Docker.
I spent more than a day on this issue. At the end, I have tried almost all possible approaches and finally solved the issue by switching to Serverless from ClaudiaJS. For use of everyone I will mention here the approaches I tried with the results.
Used the same localhost environment inside the build docker container used by the GoCD pipeline (Same node version, same yarn version, Ubuntu 16:04). But issue was still there.
Removed docker and setup the GoCD pipeline to run directly on the build server (Again used the same node version, same yarn version, Ubuntu 16:04 as I used in my local machine). But again there was no lock and issue was there without any change.
Committed the node_modules folder and build folder of my local machine to the git repository and used the same node_modules and build files withing the GoCD pipeline without executing yarn and without transpiling the code on the build server. But nothing changed.
Finally, I switched to Serverless framework. In the 1st attempt I used Serverless with babel and without webpack even though serverless recommendation is to use webpack. But again the same issue was occurred when the lambda is deployed with the pipeline. The I changed the configuration to use webpack with serverless. Then all the issues were resolved and lambda was deployed successfully. This is the webpack.config.js I used at the end.
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const build = {
entry: slsw.lib.entries,
resolve: {
extensions: ['.js'],
},
target: 'node',
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
],
},
],
},
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
optimization: {
// Do not minimize the code.
minimize: false,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
externals: [nodeExternals()],
};
module.exports = build;
This error occurs me when my serverless instance is going to read a .json file and extract a json object out of it. so i created that json object inside the script as a json object. then everything was fine.. I used basic configuration for webpack.config
Let me prefix this by saying that I do not have specific experience with GoCD, but I have run into this error in other contexts.
One potential cause for this error is a file permissions issue in deploying the code to the VM.
The error is a generic error which means that a Lambda function was unable to start. You can receive this error inside of AWS as well. Unfortunately the logging level that you see with GoCD appears to be at the same level as AWS CloudWatch, which is not very good and does not tell you what prevented Lambda from starting. You need more logging to determine the exact cause in your situation.
If you do happen to experience this error in AWS, open your Lambda function. At the top of the AWS page there should be a dropdown with a "Test" button next to it.
Open the dropdown and select "Configure Test Events." You will have to craft this test to match your specific lambda function. Next, select the new test and click the "Test" button. Lambda will show you a success or failure message with details from the call.
In my case, we had scripted the upload with the AWS sam utility on a linux box, and the file permissions were not quite right (the error was something about "permission denied, open '/var/task/index.js'").

Node process.env.VARIABLE_NAME returning undefined

I'm using environment variables on my mac to store some sensitive credentials, and trying to access them through Node. I added them into my environment profile with
export VARIABLE_NAME=mySensitiveInfo
When I use echo $VARIABLE_NAME I receive the correct output (my sensitive info).
However, when I am trying to access this same variable in Node with process.env.VARIABLE_NAME and try to print it out on the console, I get an undefined.
Other environment variables appear to be okay though. For example, when I console.log(process.env.FACEBOOK_CALLBACK_URL), it prints the correct value to my console. I added FACEBOOK_CALLBACK_URL a few days ago.
Do I have to restart my machine or something? Does it take a certain time before environment variables become available in Node? The closest answer I've seen on SO is this post, but nobody was able to figure out why it was happening.
nodemon.json file is only for setting nodemon specific configuration
So for create custom environment variables we can use dotenv package
First , Install dotenv package
npm install dotenv --save
after that create .env file in root and include environment variables as bellows
MONGO_ATLAS_PW=xxxxx
JWT_KEY=secret
Finally, inside your app.js file insert following after your imports.
require('dotenv').config()
Then you can use environment varibale like this
process.env.MONGO_ATLAS_PW
process.env.JWT_KEY
process.env.VARIABLE_NAME returns undefined because the Node.js execution environment does not know the newly added VARIABLE_NAME yet. To fix the issue, the Node.js execution environment (e.g. IDE) need to restart.
The following steps can be used to reproduce this issue:
Open IDE such as WebStorm and write a simple Node.js program: console.log(process.env.VARIABLE_NAME). It will print undefined as expected, as VARIABLE_NAME is not defined yet. Keep the IDE running, don't close it.
Open environment profile such as .bash_profile and add export VARIABLE_NAME=mySensitiveInfo in it.
Open system console and run source .bash_profile, so that the above export statement will be executed. From now on, whenever system console is opened, VARIABLE_NAME environment variable exists.
In system console, execute the Node.js program in step 1, it will print mySensitiveInfo.
Switch to IDE and execute Node.js program, it will print undefined.
Restart the IDE and execute Node.js program, this time, it will print mySensitiveInfo
I got a problem just now , and I use this solved it in webpack config
const plugins = [
new webpack.NoEmitOnErrorsPlugin(),
// after compile global will defined `process.env` this Object
new webpack.DefinePlugin({
BUILD_AT : Date.now().toString(32),
DEBUG: process.env.NODE_ENV !== 'production',
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV || "development"),
'VARIABLE_NAME': JSON.stringify(process.env.VARIABLE_NAME)
}
})
]
For everyone who might have this issue in the future and none of the solutions above are working, it may also be because you're running the node <filename>.js in a subfolder or subdirectory, and since your .env file is in the root folder, processs.env.<variable> will always return undefined.
A simple way to check is to try the following code 👉
const test = require('dotenv').config()
console.log(test)
In the console we get the following error
{ error: Error: ENOENT: no such file or directory, open 'C:\Users\vxcbv\Desktop\voisascript-auth\model\.env'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at Object.config (C:\Users\vxcbv\Desktop\voisascript-auth\node_modules\dotenv\lib\main.js:72:42)
at Object.<anonymous> (C:\Users\vxcbv\Desktop\voisascript-auth\model\db.js:1:32)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'C:\\Users\\vxcbv\\Desktop\\voisascript-auth\\model\\.env' } }
Emphasis on the Error: ENOENT: no such file or directory, open.
To solve this, just navigate back to the root and run the file from there, but specify the full path of the file from the root, like 👉
node /<subfolder>/<file.js>
please check the dir of .env file, If it is in same file as your app.js or (abc.js) than move .env to one level up
Close the code Runner Or Ide environment once and reopen it.
If you use VS code, close it completely. (Or CMD or Power Shell or ...)
I had the same issue. In my case the env file and db.js was inside a subfolder configs.
So, in index/server.js , while importing the dotven , I used
require('dotenv').config({path: './configs/.env'});
This way my env variables were being accessed.
Hope this example of mine helps you! 😀

Sails.js/Condolidate/Twig Error

I'm getting the following error when I request a view in Sails that is using Twig.js:
error: Sending 500 ("Server Error") response:
TypeError: engine is not a function
at /usr/lib/node_modules/sails/node_modules/consolidate/lib/consolidate.js:479:61
at /usr/lib/node_modules/sails/node_modules/consolidate/lib/consolidate.js:143:5
at Promise._execute (/usr/lib/node_modules/sails/node_modules/bluebird/js/release/debuggability.js:300:9)
at Promise._resolveFromExecutor (/usr/lib/node_modules/sails/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/usr/lib/node_modules/sails/node_modules/bluebird/js/release/promise.js:79:10)
at promisify (/usr/lib/node_modules/sails/node_modules/consolidate/lib/consolidate.js:136:10)
at Function.exports.twig.render (/usr/lib/node_modules/sails/node_modules/consolidate/lib/consolidate.js:473:10)
at /usr/lib/node_modules/sails/node_modules/consolidate/lib/consolidate.js:164:27
at /usr/lib/node_modules/sails/node_modules/consolidate/lib/consolidate.js:98:5
at tryToString (fs.js:456:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:443:12)
I've tried to fix this many different ways, but I'm still getting the error. I understand Sails should allow me to use anything supported by Consolidate.js, but it just isn't working.
I have:
cleared the NPM cache
installed Twig.js (v1.10.4) using NPM, and it's in my package.json
Removed and reinstalled twig
set the engine to 'twig' in config/views.js
This is a fresh Sails project without any other customizations or additions.
I'm a little new to node and sails, any help is appreciated!
Looks like there's a bug with the Sails v0.12.x handling of Twig. The easiest workaround is to install Consolidate yourself as a dependency of your project:
npm install --save consolidate
and then in your config/views.js do:
engine: {
ext: 'twig',
fn: require('consolidate').twig
}

Resources