Vue/Node error : Rule can only have one resource source - node.js

I am brand new to Vue and Node and everything was going well with a Vue3 project I was messing around with to learn. I wanted to use scss files so installed sass-loader via npm using:
npm install sass-loader sass webpack --save-dev
And since then the app is broken, now when I try to serve I get the following error:
Error: Rule can only have one resource source (provided resource and test + include + exclude) in {
"exclude": [
null
],
"use": [
{
"loader": "C:\\pathtoapp\\node_modules\\cache-loader\\dist\\cjs.js",
"options": {
"cacheDirectory": "C:\\pathtoapp\\node_modules\\.cache\\babel-loader",
"cacheIdentifier": "43be597c"
},
"ident": "clonedRuleSet-38.use[0]"
},
{
"loader": "C:\\pathtoapp\\node_modules\\babel-loader\\lib\\index.js",
"options": "undefined",
"ident": "undefined"
}
]
}
Error: Rule can only have one resource source (provided resource and test + include + exclude) in {
"exclude": [
null
],
"use": [
{
"loader": "C:\\pathtoapp\\node_modules\\cache-loader\\dist\\cjs.js",
"options": {
"cacheDirectory": "C:\\pathtoapp\\node_modules\\.cache\\babel-loader",
"cacheIdentifier": "43be597c"
},
"ident": "clonedRuleSet-38.use[0]"
},
{
"loader": "C:\\pathtoapp\\node_modules\\babel-loader\\lib\\index.js",
"options": "undefined",
"ident": "undefined"
}
]
}
I looked up this error and most believed this to be an issue with webpack but I have uninstalled and installed again. Installed an earlier version of webpack, tried changing package.json to point to an earlier version, tried anything I can currently find on SO and now I'm completely stumped.
Any assistance on this would be much appreciated as I'd rather learn and discover how to fix the problem should I encounter it again rather than simply start a new project. Let me know any code/files I should post in an edit where required.

I ran into the same issue and I was able to resolve it by:
rm -rf node_modules
rm package-lock.json
npm install --legacy-peer-deps
Source

Related

Nx - how to import from another module when building with the tsc executor?

I have a problem that is similar to the one described in Building library with imports from another library using NX Monorepo.
Using nx monorepo with a node app and a library. The app is built with #nrwl/js:tsc (not webpack as it is by default) and then executed using #nrwl/node:node. This is what the project.json looks like:
"build": {
"executor": "#nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"main": "apps/dep/src/main.ts",
"outputPath": "dist/apps/dep",
"tsConfig": "apps/dep/tsconfig.app.json"
}
},
"serve": {
"executor": "#nrwl/node:node",
"options": {
"buildTarget": "dep:build"
}
},
Importing anything from another library causes a problem with the build due to files not being under rootDir:
import { MyEnum } from '#zorro/types';
This I resolved using the advice from the question above, adding the following settings to tsconfig.app.json:
"compilerOptions": {
...
"incremental": false,
"paths": { "#zorro/*": ["dist/libs/*"] }
},
This made tsc work, but when running with node, I get an error:
Error: Cannot find module '#zorro/types'
Can't figure out what needs to be changed in order to properly resolve the path of the library for the compiled main.js file.

Make "import/extensions" require the .js extension in a Node.js TypeScript project

First of all, some facts:
Node.js requires that all local imports include the imported module's extension (e.g. import hello from './hello.js', not import hello from './hello').
TypeScript will compile imports with or without the .js extension, which means a missing .js extension is a runtime error.
TypeScript doesn't transform imports to add the .js extension or convert .ts to .js.
In my Node.js project, I want to make missing a missing .js extension be a build-time error using the import/extensions ESLint rule. However, when I enable this rule using the following configuration:
{
"root": true,
"env": {
"node": true
},
"parser": "#typescript-eslint/parser",
"plugins": [
"#typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:#typescript-eslint/eslint-recommended",
"plugin:#typescript-eslint/recommended"
],
"settings": {
"import/resolver": {
"typescript": {},
"node": {
"extensions": [".js"]
}
}
},
"rules": {
"import/extensions": ["error", "ignorePackages"]
}
}
running eslint gives me the following error:
/sandbox/src/index.ts
1:19 error Missing file extension "ts" for "./hello.js" import/extensions
Source files:
// index.ts
import hello from "./hello.js";
hello();
// hello.ts
export default function hello() {
console.log("Hello");
}
CodeSandbox link: https://codesandbox.io/s/elated-germain-13glp7
I fixed this with the following config:
{
"root": true,
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:#typescript-eslint/eslint-recommended",
"plugin:#typescript-eslint/recommended"
],
"rules": {
"import/extensions": ["error", "ignorePackages"],
"import/no-unresolved": "off"
}
}
The main thing is to disable the "import/no-unresolved" rule and remove "settings"."import/resolver"."node". ("import/no-unresolved" is redundant as unresolved imports are resolved at the compilation stage.) Other items removed here were already being added as a result of extending the #typescript-eslint plugins.
I found an eslint plugin that can fix missing .js extensions for imports in .ts files, instead of just showing an error:
https://github.com/AlexSergey/eslint-plugin-file-extension-in-import-ts
https://www.npmjs.com/package/eslint-plugin-file-extension-in-import-ts
Install:
npm i -D eslint-plugin-file-extension-in-import-ts
Add to .eslintrc file:
{
"plugins": [
"file-extension-in-import-ts"
],
"rules": {
"file-extension-in-import-ts/file-extension-in-import-ts": "error"
}
}
NOTE: I ran into an issue similar to https://github.com/import-js/eslint-plugin-import/issues/1292 when using this package, and it will incorrectly try to add .js extensions on these paths when fixing automatically.
You could try ts-add-js-extension package to append .js extension to the transpiled JavaScript files. After you install you can do
ts-add-js-extension add --dir={your-transpiled-outdir}

Make Yarn don't hoist the dependencies of the specific package

In below project, I want all dependencies of TodoList will no be hosted to node_modules in root directory of monorepo.
Below settings is not enough to reach this effect:
{
"private": true,
"workspaces": {
"packages": [ "BusinessRules", "Server", "TodoList" ],
"nohoist": [
"TodoList/**"
]
}
}
"TodoList/**/**" is not enough too.
How to make all dependencies of TodoList will be inside TodoList/node_modules?
Found the solution here.
In this case, it's required to add below JSON in TodoList/package.json:
"workspaces": {
"nohoist": ["**"]
},

Configure JSON in Arkit to visualize NPM modules in Package.json

I am using the following npm package named arkit in order to create architecture diagrams of node.js projects, but I am unable to visualize npm packages (dependencies folder) in my node.js application architecture as depicted in the examples of Arkit and Vue/Nuxt TodoMVC, I tried to follow the json configuration of each of their respective arkits but either they are non-existent like in Vue or vague like in Arkit itself.
I used the config given in arkit configuration example but I end up with all dependencies of main dependencies like this. I tried the following config
{ "$schema": "https://arkit.pro/schema.json",
"excludePatterns": ["test/**", "tests/**", "**/*.test.*", "**/*.spec.*"],
"components": [
{ "type": "Dependency",
"patterns": ["node_modules/**/*.js"] },
{ "type": "Component",
"patterns": ["**/*.js", "**/*.jsx"]
}
],
"output": [
{ "path": "arkit.svg",
"groups": [ { "first": true, "components": ["Component"] },
{
"type": "Dependencies",
"components": ["Dependency"]
}
]
}
]
}
but it crashed during architecture generation, I also emailed the owner of this npm package and one other person who successfully managed to do so, but they are busy to guide me in configuring JSON of arkit.
Can I use the for-of loop in the JSON config file in order to get only those node_modules which are included in package.json as I don't want to get additional sub-dependencies of the main npm packages in the architecture representation as depicted in the link shared above!
TL;DR
I want diagrams with dependencies like these but I am getting this
I tried, adding --depth=0 in the command line "npx arkit --config test.json --depth=0" but no luck
I think arkit expects output.path to be an array - but you are passing it a string. Try using the modified config:
{
"$schema": "https://arkit.pro/schema.json",
"excludePatterns": ["test/**", "tests/**", "**/*.test.*", "**/*.spec.*"],
"components": [{
"type": "Dependency",
"patterns": ["node_modules/*"]
},
{
"type": "Component",
"patterns": ["**/*.js", "**/*.jsx"]
}
],
"output": [{
"path": ["arkit.svg"],
"groups": [{
"first": true,
"components": ["Component"]
},
{
"type": "Dependencies",
"components": ["Dependency"]
}
]
}]
}
It's working on Ubuntu as if there are more reasons to hate Windows 10. I implemented the package.json config of the authors Vue application and viola it worked like a charm. 2 months of looking for answers and trying everything on Windows, Ubuntu did the trick

#angular/cli: 1.4.1 Angular Generate Component but it returns home.component.css

$npm install -g #angular/cli
$ng new angular --routing --style=sass
$ng g c home
"apps": [
{
"styles": [
"styles.sass"
],
}
"defaults": {
"styleExt": "sass",
"component": {
}
}
I want to sass style in angular, I use angular cli, I try to generate component it returns with style with prefix css. May you help me to fixing that? Thanks in advance for your answer.
To override the default style, you can use the option --style [css|scss|sass]:
ng g c home --style=css
I just migrated from #angular/cli#1.0.3 to #angular/cli#1.4.2 and I am facing the same issue. Turns out it's due to a bug introduced in v1.4.1 so we can only wait for a new angular-cli release that will fix this bug.
In v1.4.1 also the apps.prefix is ignored but this was fixed in v1.4.2.
In the mean time, the workaround provided by #Derlin can be used.
github issues on this topic:
https://github.com/angular/angular-cli/issues/7624
https://github.com/angular/angular-cli/issues/7682
https://github.com/angular/angular-cli/issues/7644
https://github.com/angular/angular-cli/issues/7647
https://github.com/angular/angular-cli/issues/7522
update:
The issue is fixed in #angular/cli#1.4.3. Check this release note.
#angular/cli: Generating component considers default style extension
for project now
Here is my defaults that works :
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
Otherwise, you can just rename it.

Resources