Angular 2 Protractor cannot require .scss files - sass

I'm trying to run a Protractor Test using Angular 2 and Webpack
Partial Webpack config:
resolve: {
extensions: ['', '.ts', '.js', '.scss', '.css']
},
module: {
loaders: [
// TypeScript
{ test: /\.ts$/, loader: 'ts-loader'},
// SCSS
{ test: /\.scss$/, exclude: /node_modules/, loaders: ['raw-loader', 'sass-loader']}
]
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(true)
]
My home.component.ts
import { Component, Injectable } from '#angular/core';
#Component({
selector: 'home',
styles: [require('./home.component.scss')],
template: `<h4 class="page-home">Home</h4>`
})
#Injectable()
export class Home {}
And my home.component.scss
.page-home {
color: blue;
}
And my E2E:
require('../server');
describe('App', () => {
beforeEach(() => {
browser.get('/');
});
it('should have a title', (done) => {
let subject = browser.getTitle();
subject
.then((data) => {
let result = 'test';
expect(data).toEqual(result);
done();
});
});
it('should definitely pass', () => {
expect(true).toEqual(true);
});
});
I run the server and everything comes up as expected. When I run my E2E tests I get the following error:
[14:42:47] I/hosted - Using the selenium server at http://hub.browserstack.com/wd/hub
[14:42:47] I/launcher - Running 1 instances of WebDriver
[14:43:03] E/launcher - Error: /app/src/app/home/home.component.scss:1
(function (exports, require, module, __filename, __dirname) { .page-home {
^
SyntaxError: Unexpected token .
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at home.component.ts:5:12
at Object.<anonymous> (home.component.ts:9:21)
[14:43:03] E/launcher - Process exited with error code 100
npm info lifecycle cnd-app#1.0.0~protractor: Failed to exec protractor script
npm ERR! Linux 3.19.0-59-generic
npm ERR! argv "/usr/local/bin/node" "/app/node_modules/.bin/npm" "run" "protractor"
npm ERR! node v6.2.0
npm ERR! npm v3.9.2
npm ERR! code ELIFECYCLE
npm ERR! cnd-app#1.0.0 protractor: `protractor protractor.conf.js`
npm ERR! Exit status 100
It seems like protractor uses require different than how WebPack treats it.Is there a config for this or anything I am missing?
** Update **
I am able to resolve the issue. I have a typescript register causing conflict in the protractor.conf.js.

Related

Laravel Breeze Vite Dev-Server Error: "cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file"

I set up a fresh Laravel Breeze Project with Vite. When I run:
npm run dev
I get this Error:
failed to load config from PATH/vite.config.js
error when starting dev server:
Error: cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: PATH/dist/client/client.mjs
at testCaseInsensitiveFS (PATH/node_modules/vite/dist/node-cjs/publicUtils.cjs:3420:15)
at Object.<anonymous> (PATH/node_modules/vite/dist/node-cjs/publicUtils.cjs:3425:1)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Object._require.extensions.<computed> [as .js] (file:///PATH/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:63517:17)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (PATH/node_modules/vite/index.cjs:7:31)
I can't find any Information about this error! A few Weeks ago I had no Problems with this.
Here is my Vite Config File:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: true,
}),
],
});
Thanks in advance
Make sure that your project path doesn't contain any special character like #.

Unknown word error building a Chrome Extension using Laravel-mix with vue3

I'm in the process of building a chrome-extension manifest Version3 in vue.js 3 using laravel-mix. In order to prevent styles leaking between the extension code and the current browser tab, I've loaded the content-scripts code into a shadow-dom element. This is working however as the default compiling process from laravel-mix is to add the styles in a style tag in the head of the document, currently the css styling is being prevented from reaching the very place it should be isolated to. I've tried following the laravel-mix documentation that suggests using a function that lazy loads the style tag within the shadow dom element however I am getting this error and cannot work out what is wrong - guessing there is missing configs. Thanks in advance for any help.
Error Details
ERROR in ./src/assets/css/content_shinego.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/laravel-mix/node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(4:7) C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\src\assets\css\content_shinego.css Unknown word
2 | var exported = {};
3 |
4 | import API from "!../../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
| ^
5 | import domAPI from "!../../../node_modules/style-loader/dist/runtime/styleDomAPI.js";
6 |
at processResult (C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\webpack\lib\NormalModule.js:758:19)
at C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\webpack\lib\NormalModule.js:860:5
at C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\loader-runner\lib\LoaderRunner.js:400:11
at C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\loader-runner\lib\LoaderRunner.js:252:18
at context.callback (C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\loader-runner\lib\LoaderRunner.js:124:13)
at Object.loader (C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\laravel-mix\node_modules\postcss-loader\dist\index.js:140:7)
ERROR in ./src/assets/css/popup_shinego.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/laravel-mix/node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(4:7) C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\src\assets\css\popup_shinego.css Unknown word
2 | var exported = {};
3 |
4 | import API from "!../../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
| ^
5 | import domAPI from "!../../../node_modules/style-loader/dist/runtime/styleDomAPI.js";
6 |
at processResult (C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\webpack\lib\NormalModule.js:758:19)
Capture\draft\node_modules\loader-runner\lib\LoaderRunner.js:400:11 at C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\loader-runner\lib\LoaderRunner.js:252:18 at context.callback (C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\loader-runner\lib\LoaderRunner.js:124:13) at Object.loader (C:\Users\ollie\Documents\Shine\ChromeExtensionScreenCapture\draft\node_modules\laravel-mix\node_modules\postcss-loader\dist\index.js:140:7)
2 ERRORS in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
webpack compiled with 4 errors
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yobi-chrome#0.1.0 local: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --env=local --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yobi-chrome#0.1.0 local script.
npm ERR! C:\Users\ollie\AppData\Roaming\npm-cache_logs\2022-08-30T10_09_41_700Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yobi-chrome#0.1.0 dev: npm run local
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yobi-chrome#0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ollie\AppData\Roaming\npm-cache_logs\2022-08-30T10_09_41_718Z-debug.log
webpack.mix.js file
let mix = require('laravel-mix')
let path = require('path')
mix.setPublicPath('./')
mix.alias({
'#': path.join(__dirname, 'src')
});
mix.css('src/assets/css/content_shinego.css', 'dist/assets/css')
.css('src/assets/css/popup_shinego.css', 'dist/assets/css')
.css('src/assets/css/font-awesome.min.css', 'dist/assets/css')
.css('src/assets/css/mdbvue.css', 'dist/assets/css')
mix.js('src/popup/popup.js', 'dist/popup')
.js('src/content_scripts/content.js', 'dist/content_scripts')
.vue();
mix.copy('src/manifest.json', 'dist/')
.copy('src/background.js', 'dist/')
.copy('./css-loader-shim.js', 'dist/')
.copy('src/popup/popup.html', 'dist/popup')
.copy('src/assets/img/', 'dist/assets/img')
.copy('src/assets/icons/', 'dist/assets/icons')
.options({
processCssUrls: false
})
mix.webpackConfig({
module: {
rules: [
{
test: /\_shinego.css$/,
include: path.resolve(__dirname, 'src/assets/css'),
use: [
{
loader: "style-loader",
options: {
injectType: "lazyStyleTag",
insert: function insertIntoTarget(element, options) {
var parent = options.target || document.head;
parent.appendChild(element);
}
},
}
],
}
]
}
});
** Relevant package.json **
"dependencies": {
"#fortawesome/vue-fontawesome": "^2.0.8",
"axios": "^0.27.2",
"bootstrap-vue": "^2.22.0",
"fibers": "^5.0.2",
"fontawesome-free": "^1.0.4",
"lodash": "^4.17.21",
"mdb-vue-ui-kit": "^2.0.0",
"mdbvue": "git+https://oauth2:***#git.mdbootstrap.com/mdb/vue/vu-pro.git",
"postcss-loader": "^7.0.1",
"sass": "^1.54.4",
"vue-shadow-dom": "^4.2.0"
},
"devDependencies": {
"#types/chrome": "^0.0.194",
"#types/webpack-env": "^1.18.0",
"#vue/compiler-sfc": "^3.2.37",
"cross-env": "^7.0.3",
"laravel-mix": "^6.0.49",
"style-loader": "^3.3.1",
"types": "^0.1.1",
"vue": "^3.2.37",
"vue-loader": "^16.8.3",
"vue-template-compiler": "^2.7.9",
"webpack": "^5.74.0"
}

Reference Error :cy is not defined while running cypress test

Describe('The Login', function () {
beforeEach(function () {
cy.readFile(Cypress.env('test')).as("user")});
it("Login", () => {
cy.get("#user").then((user) =>
cy.login(user.username, user.password))})
FAIL cypress/integration/login.spec.js
● The Login Page ›
ReferenceError: cy is not defined
at Object.<anonymous> (cypress/integration/login.spec.js:4:5)
at new Promise (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
To add some context to the answer by #sai, to resolve this eslint error all I had to do was install eslint-plugin-cypress from here.
npm install eslint-plugin-cypress --save-dev
Then, in my eslint config I added one line to my extends array.
Your config could be .eslintrc.json or the "eslintConfig" configuration object in your package.json
{
"extends": [
"plugin:cypress/recommended"
]
}
Testing locally, this should work for you. Change path of your json file, and use your custom command cy.login. In my example I just printed variables to console.
describe('The Login', () => {
beforeEach(() => {
cy.readFile('cypress/integration/test/test.json').as("user")});
it("Login", () => {
cy.get("#user").then((user) =>
cy.log(user.username, user.pass))
})
})
My test.json was:
{
"username":"test#test.com",
"pass":"pass"
}
The issue was related to eslint
Had to install few packages and made an update to eslintrc files

Vuejs Laravel blankpage on IE and Safari

My webapp work correctly on Chrome and Firefox but not with IE8-11 and Safari.
I use Laravel 5.6 and the last version of VueJS (with laravelmix webpack).
I supposed that the const variable type is not readable by IE and Safari (
I think it would be necessary to compile es6 in es5).
I've tried import babel in app.js file but also many library but with no result:
- npm install es6-promise
- npm i --save #babel/polyfill
- npm i babel-polyfill
- npm i bufferutil --save -optional
- .babelrc file in root
- npm i --save-dev babel-preset-stage-2
- npm i --save-dev babel-cli babel-preset-es2015
- npm i --save-dev babel-preset-env
- npm i joi-browser
- npm i --save-dev babel-preset-es2015-node6
- npm i --save-dev babel-preset-stage-0
Or laravelmix file (webpack.mix.js) should be able to with the right config?
I've tried also this:
- in webpack.mix.js file
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
mix.webpackConfig({
node: {
fs: 'empty'
}
});
// mix.webpackConfig({
// module: {
// rules: [
// {
// test: /\.js?$/,
// use: {
// loader: 'babel-loader',
// options: {
// presets: ['es2015'] // default == env
// }
// }
// }
// ]
// }
// });
// OR
// mix.webpackConfig({
// module: {
// rules: [{
// test: /\.js?$/,
// exclude: /(bower_components)/,
// use: [{
// loader: 'babel-loader',
// options: mix.config.babel()
// }]
// }]
// }
// });
.babelrc file:
{
"presets": ["es2015"]
}
and
{
"presets": [
[
"env",
{
"modules": false,
"browsers": ["IE >= 9", "> 1%"]
}
],
"stage-2"
],
"plugins": ["transform-runtime"],
"comments": false
}
If you have solutions or had a similar case, do not hesitate.
I've already searched on the web and by myself but nothing work.
If you need more information, tell me in comment.
EDIT:
ERROR MSG : SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode. (safari)

Webpack SASS loader with alias not compiling under Mocha

I have a component that loads styles like this. The css directory is somewhere else; here it is being used as a Webpack alias.
import 'css/components/PromptText';
// ...
class PromptText extends React.Component {
// ...
}
Here is my webpack.config.json:
var path = require('path');
module.exports = {
entry: './src/index.jsx',
output: {
path: 'dist',
filename: 'app.bundle.js',
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
}, {
test: /\.json/,
exclude: /node_modules/,
loader: 'json',
}, {
test: /\.scss/,
exclude: /node_modules/,
loaders: ['style', 'css', 'sass'],
}],
},
resolve: {
alias: {
css: 'css', // <-- Alias here
},
root: path.resolve(__dirname),
extensions: ['', '.js', '.jsx', '.scss'],
},
};
Now, I have a test like this for Mocha:
import PromptText from '../../src/components/PromptText';
describe('PromptText', () => {
it('should display words');
});
When Mocha imports the component, it also tries to load the CSS component. There are two problems with this:
The css directory has been aliased. Mocha needs to know where the alias points. To fix this, I have installed the babel-plugin-webpack-alias package, with the following .babelrc:
{
"presets": ["es2017", "react", "stage-0"],
"env": {
"test": {
"plugins": [
["webpack-alias", {"config": "webpack.config.js"}]
]
}
}
}
CSS can't be imported by Mocha, so it needs to be ignored. I use the ignore-styles package and invoke Mocha as mocha --compilers js:babel-core/register --require ignore-styles.
Despite having done these two things, I get the following error when trying to run tests:
(cd data && make)
make[1]: Nothing to be done for `all'.
NODE_ENV=test ./node_modules/.bin/mocha --compilers js:babel-core/register --require ignore-styles \
$(find test -type f -name 'test*.js')
module.js:341
throw err;
^
Error: Cannot find module 'css'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/waleed/Workspace/js/steno/src/components/PromptText.jsx:2:1)
at Module._compile (module.js:413:34)
at loader (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .jsx] (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/waleed/Workspace/js/steno/test/components/testPromptText.js:2:1)
at Module._compile (module.js:413:34)
at loader (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at /Users/waleed/Workspace/js/steno/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/waleed/Workspace/js/steno/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/Users/waleed/Workspace/js/steno/node_modules/mocha/lib/mocha.js:485:10)
at Object.<anonymous> (/Users/waleed/Workspace/js/steno/node_modules/mocha/bin/_mocha:403:18)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3
make: *** [test] Error 1
For some reason, the css alias isn't being resolved. However, this error only happens sometimes, unpredictably. In order to consistently recreate this error, I have to set BABEL_DISABLE_CACHE=1 in the environment.
How can I get my Mocha test to correctly import and ignore the CSS file?
In order to fix this, I switched from the babel-plugin-webpack-alias to the babel-plugin-webpack-aliases package, and update my .babelrc to use it:
{
"presets": ["es2017", "react", "stage-0"],
"env": {
"test": {
"plugins": [
["webpack-aliases", {"config": "webpack.config.js"}]
]
}
}
}
I also always run mocha with BABEL_DISABLE_CACHE=1 set in the environment. (I think this is undoing the damage that babel-plugin-webpack-alias did; it may not be necessary on every run if that package was never used.)

Resources