rollup in watch mode building with two versions of rollup - rollup

I have an odd problem as of late. When I run rollup -cw, Rollup bundles my app with Rollup v2.2.0. Everything's fine.
rollup v2.2.0
bundles ./src/index.html → build...
[Browsersync] Access URLs:
----------------------------------
Local: http://localhost:8000
External: http://10.0.0.13:8000
----------------------------------
UI: http://localhost:3001
UI External: http://localhost:3001
----------------------------------
[Browsersync] Serving files from: build
[Browsersync] Watching files...
(!) Circular dependencies
src/apollo/client.js -> src/apollo/resolvers/index.js -> src/apollo/resolvers/Query.js -> src/router/router.js -> src/apollo/auth.js -> src/apollo/client.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/select.js -> node_modules/d3-selection/src/selection/index.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/selectAll.js -> node_modules/d3-selection/src/selection/index.js
...and 17 more
(!) Generated an empty chunk
index
created build in 30.8s
[2020-03-26 23:42:30] waiting for changes...
[Browsersync] Reloading Browsers...
[Browsersync] Reloading Browsers... (buffered 302 events)
But if I subsequently save a file, rollup will bundle the app with rollup v1.31.1
rollup v1.31.1
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build, build/nomodule...
bundles ./src/index.html → build...
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
Error: EEXIST: file already exists, mkdir 'build/assets/systemjs/dist'
[!] (plugin Rollup Core) Error: Could not load /path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js (imported by /path/to/the-app/node_modules/#material/mwc-fab/mwc-fab-base.js): ENOENT: no such file or directory, open '/path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js'
Error: Could not load /path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js (imported by /path/to/the-app/node_modules/#material/mwc-fab/mwc-fab-base.js): ENOENT: no such file or directory, open '/path/to/the-app/node_modules/#material/mwc-fab/node_modules/#material/mwc-ripple/ripple-directive.js'
(!) Circular dependencies
src/apollo/client.js -> src/apollo/resolvers/index.js -> src/apollo/resolvers/Query.js -> src/router/router.js -> src/apollo/auth.js -> src/apollo/client.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/select.js -> node_modules/d3-selection/src/selection/index.js
node_modules/d3-selection/src/selection/index.js -> node_modules/d3-selection/src/selection/selectAll.js -> node_modules/d3-selection/src/selection/index.js
...and 17 more
(!) Generated an empty chunk
index
created build in 31s
[2020-03-26 23:44:09] waiting for changes...
[Browsersync] Reloading Browsers...
Note that this second build also builds the production version (nomodule)
I don't have rollup v1.31.1 installed in this repo
AFAICT I have no packages that require rollup v1.31.1
> npm ls rollup
the-app#0.1.0 /path/to/the-app
├─┬ #open-wc/demoing-storybook#1.13.8
│ └── rollup#1.32.1
├── UNMET PEER DEPENDENCY rollup#2.2.0
└─┬ rollup-plugin-workbox#5.0.1
└─┬ workbox-build#5.0.0
└── rollup#1.32.1
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-alias#3.0.1
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-beep#0.1.2
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-commonjs#11.0.2
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-json#4.0.2
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-node-resolve#7.1.1
npm ERR! peer dep missing: rollup#^1.20.0, required by #rollup/plugin-replace#2.3.1
npm ERR! peer dep missing: rollup#^0.65.2 || ^1.0.0, required by rollup-plugin-minify-html-literals#1.2.3
npm ERR! peer dep missing: rollup#^1.4.1, required by rollup-plugin-notify#1.1.0
I don't have rollup installed globally, having run yarn global remove rollup and npm r -g rollup
Here's my rollup.config.js
import dotenv from 'dotenv';
import path from 'path';
import alias from '#rollup/plugin-alias';
import beep from '#rollup/plugin-beep';
import commonjs from '#rollup/plugin-commonjs';
import json from '#rollup/plugin-json';
import replace from '#rollup/plugin-replace';
import resolve from '#rollup/plugin-node-resolve';
import { generateSW } from 'rollup-plugin-workbox';
import { terser } from 'rollup-plugin-terser';
import babel from 'rollup-plugin-babel';
import browsersync from 'rollup-plugin-browsersync';
import copy from 'rollup-plugin-copy';
import graphql from '#kocal/rollup-plugin-graphql';
import html from '#open-wc/rollup-plugin-html';
import litcss from 'rollup-plugin-lit-css';
import minifyLitHtml from 'rollup-plugin-minify-html-literals';
import notify from 'rollup-plugin-notify';
import watchAssets from 'rollup-plugin-watch-assets';
dotenv.config();
const PROCESS_WATCHING =
!!(process.argv.some(arg => !!arg.match(/-c?w/)) || process.argv.includes('--watch'));
const production = !PROCESS_WATCHING && process.env.NODE_ENV === 'production';
const replaceConfig = {
...redacted
};
const targets = [
{ src: 'node_modules/systemjs/dist', dest: 'build/assets/systemjs' },
{ src: 'node_modules/#webcomponents', dest: 'build/assets' },
{ src: 'src/favicon.ico', dest: 'build' },
{ src: 'src/favicon.ico', dest: 'build' },
{ src: 'src/manifest.webmanifest', dest: 'build' },
{ src: 'src/assets', dest: 'build' },
{ src: 'src/components/shared.css', dest: 'build' },
{ src: 'src/index.html', dest: 'build' },
{ src: 'src/*.css', dest: 'build' },
];
const customResolver = resolve({
extensions: ['.js', '.json', '.html', '.graphql', '.css'],
dedupe: id => id.includes('lit'),
});
const entries = [{
find: /#(.*)\/(.*)\b/,
replacement: path.resolve(__dirname, 'src/$1/$2'),
}, {
find: /#(.*)\b/,
replacement: path.resolve(__dirname, 'src/$1'),
}];
const esmOutput = {
format: 'esm',
dir: 'build',
sourcemap: true,
};
const nomoduleOutput = {
format: 'system',
dir: 'build/nomodule',
sourcemap: true,
};
const productionOutput = [esmOutput, nomoduleOutput].map(output => ({
...output,
plugins: [
terser(),
minifyLitHtml(),
generateSW(require('./workbox-config.js')),
],
}));
export default {
input: './src/index.html',
output: production ? productionOutput : esmOutput,
watch: {
include: 'src/**',
clearScreen: false,
},
plugins: [
html({ minify: production }),
babel(),
graphql(),
json(),
litcss({ uglify: production }),
customResolver,
alias({ entries, customResolver }),
replace(replaceConfig),
commonjs({ sourceMap: false }),
copy({ targets, copyOnce: PROCESS_WATCHING }),
...PROCESS_WATCHING ? [
watchAssets({ assets: ['src/**/*.html', 'src/**/*.css'] }),
browsersync({
port: 8000,
server: 'build',
single: true,
watch: true,
watchOptions: {
awaitWriteFinish: {
ignoreInitial: true,
stabilityThreshold: 2000,
pollInterval: 100,
ignore: '/assets/**/*',
},
},
}),
] : [],
beep(),
notify(),
],
// Don't warn about `this` - typescript produces these.
onwarn(warning, warn) {
if (warning.code === 'THIS_IS_UNDEFINED') return;
warn(warning);
},
};
What I've Tried
I've tried downgrading to rollup 1.32
I've tried npm dedupe rollup
I've tried yarn global remove rollup
I've tried rm -rf node_modules ; rm package-lock.json ; npm i
I've tried commenting out these plugins:
watchAssets
browsersync
copy
beep
notify
html
I've tried adding this plugin:
{
name: 'sanity-check',
buildStart() {
if (production) console.log('HEY!!!! IT\'S PRODUCTION');
},
},
No logs appeared
No dice.
What is causing this double-build behaviour, and where is rollup 1.31.1 coming from?
Update
Grepping node_modules for 1.31.1 produced this result
$ rg "1\.31\.1" node_modules/#surma
node_modules/#surma/rollup-plugin-off-main-thread/package.json
55: "rollup": "1.31.1"
$ npx npm-why #surma/rollup-plugin-off-main-thread
npx: installed 4 in 1.141s
Who required #surma/rollup-plugin-off-main-thread:
my-pwa > rollup-plugin-workbox > workbox-build > #surma/rollup-plugin-off-main-thread#1.2.0
So perhaps this error is caused by #surma/rollup-plugin-off-main-thread's pinning rollup to a specific version.
What I don't understand is how that makes it possible for npm to reference two rollup bins

Related

Storybook + Vue.js + Sass + npm7 workspaces won't compile

I have a project which I am breaking into multiple workspaces using npm7.
I am using sass in vue components in a package (another workspace), and importing that package into my current workspace.
When I use sass in the workspace in which storybook is running, it compiles fine.
When I use css in the other workspace it compiles fine.
When I use sass in another workspace, it doesn't find the loaders.
ModuleParseError: Module parse failed: Unexpected character '#' (39:0)
File was processed with these loaders:
* ../node_modules/vue-docgen-loader/lib/index.js
* ../node_modules/vue-docgen-loader/lib/index.js
* ../node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
|
> #import '../../../bootstrap4/scss/functions';
| #import '../../../bootstrap4/scss/variables';
|
at handleParseError (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/webpack/lib/NormalModule.js:469:19)
at /srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/webpack/lib/NormalModule.js:503:5
at /srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/webpack/lib/NormalModule.js:358:12
at /srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at iterateNormalLoaders (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
at /srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:236:3
at context.callback (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at Object.module.exports (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/vue-docgen-loader/lib/index.js:28:5)
at LOADER_EXECUTION (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:119:14)
at runSyncOrAsync (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:120:4)
at iterateNormalLoaders (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
at iterateNormalLoaders (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
at /srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:236:3
at context.callback (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at Object.module.exports (/srv/insight_lerna/submodules/insight_core/insight-javascript/node_modules/vue-docgen-loader/lib/index.js:28:5)
My main.js works for local sass. It is as follows:
const path = require('path');
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.#(js|jsx|ts|tsx)"
],
"addons": [
"#storybook/addon-links",
"#storybook/addon-essentials"
],
"webpackFinal": async (config, { configType }) => {
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});
// Return the altered config
return config;
},
}
Is it possible to use storybook with npm workspaces?
I am using storybook 6.2.8.
I am using vue.js 2.6.12
On further investigation, I found the error is in the line:
include: path.resolve(__dirname, '../'),
I removed this line and it worked fine. Clearly it is limiting the rule to the current workspace instead of all workspaces.

Vue CLI 3 remove console.log and code comments with Terser

I'm using VUE CLI 3 and I need to remove the console.log and code comments from the production built. This is my Terser setup:
webpack.config.js in src folder
module.exports = {
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {drop_debugger},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false,
},
}),
],
},
};
My production workflow: Run npm run build -> cd dist -> npm run serve
The production build still outputs all console.log statements and shows code comments (<!-- -->).
What do I need to change to remove them?
First of all: make sure you are configuring Terser correctly:
terserOptions: {
ecma: 6,
compress: { drop_console: true },
output: { comments: false, beautify: false }
}
npm run serve
is usually a shortcut for:
vue-cli-service
vue-cli-service --help
Usage: vue-cli-service <command> [options]
Commands:
serve start development server
build build for production
inspect inspect internal webpack config
lint lint and fix source files
So when your workflow is the above mentioned npm run build -> cd dist -> npm run serve then you are actually starting the dev server, which does not apply Terser.
In order to run the production build you can use any webserver capable of serving static content:
NodeJs examples:
npm install -g serve
serve -s dist
or
npm install -g node-static
static dist

why create-react-app create project and yarn start has error 'Cannot read property 'indexOf' of undefined'?

i'm use create-react-app create project, and after yarn eject, i change webpack.config.js 'entry' propetry, and paths 'module.exports={}', when i yarn start, i get the error 'Cannot read property 'indexOf' of undefined'. i don't know where is mistakes.
env: macos 14
node: v10.13.0
npm: v6.11.3
yarn: 1.15.2
react: v16.9.0
webpack.config.js:
entry: {
index: [
paths.appIndexJs,
isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient')
].filter(Boolean),
query: [
paths.appQueryJs,
isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient')
].filter(Boolean),
order: [
paths.appOrderJs,
isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient')
].filter(Boolean),
ticketPage: [
paths.appTicketPageJs,
isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient')
].filter(Boolean)
},
paths.js
module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
// this is new
appQueryHtml: resolveApp('public/query.html'),
appOrderHtml: resolveApp('public/order.html'),
appticketPageHtml: resolveApp('public/ticketPage.html'),
appIndexJs: resolveModule(resolveApp, 'src/index/index'),
appQueryJs: resolveModule(resolveApp, 'src/query/index'),
appTicketPageJs: resolveModule(resolveApp, 'src/ticketPage/index'),
appOrderJs: resolveModule(resolveApp, 'src/order/index'),
// new over
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appTsConfig: resolveApp('tsconfig.json'),
appJsConfig: resolveApp('jsconfig.json'),
yarnLockFile: resolveApp('yarn.lock'),
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
proxySetup: resolveApp('src/setupProxy.js'),
appNodeModules: resolveApp('node_modules'),
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')),
};
i expect running 'yarn start', the react project is ok!
project folder:
(source: labike.xyz)
error:
(source: labike.xyz)
i found the error in paths.js:
module.exports = {
...
appTicketPage: ...
}
i'm write error!

I want `npm run build` generate the dist assets files in the static directory

In my src/config/index.js, the build settings is bellow:
const path = require('path')
module.exports = {
build: {
env: require('./env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
},
but after I npm run build, I get the results:
shouldn't the assets file in the static directory? where is the error of config?
I want the dist directory like this:
my webpack.prod.config.js default code is bellow:
......
new HtmlWebpackPlugin({
filename: '/index.html',
template: './src/template/index.ejs',
inject: false
})
]
});
the filename: '/index.html', so, the index.html is in the above of dist directory.

Getting error while using "extract-text-webpack-plugin" with webpack : "Module build failed: Error: Parameter 'dependency' must be a Dependency"

Error while running webpack-dev-server
ERROR in ./css/app.scss
Module build failed: Error: Parameter 'dependency' must be a Dependency
at Compilation.process [as _addModuleChain] (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compilation.js:347:9)
at Compilation.process [as addEntry] (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compilation.js:423:7)
at SingleEntryPlugin.<anonymous> (/Users/roshankarki/Desktop/del_del/wp_tst/node_modules/webpack/lib/SingleEntryPlugin.js:22:15)
at Compiler.applyPluginsParallel (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/node_modules/tapable/lib/Tapable.js:107:14)
at Compiler.compile (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compiler.js:394:7)
at Compiler.runAsChild (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compiler.js:203:7)
at Object.module.exports.pitch (/Users/roshankarki/Desktop/del_del/wp_tst/node_modules/extract-text-webpack-plugin/loader.js:81:18)
webpack: bundle is now VALID.
My webpack.config.js looks like this:
var path = require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
/* this defins path where entry files are to be found */
context: path.resolve('js'),
entry: ["./utils","./app"],
output: {
/* this is output directory of bundle.js */
path: path.resolve('build/'),
/* this is path of directory where bundle will be served in server */
publicPath: '/public/assets/',
filename: "bundle.js"
},
/* this plugin helps to generate seperate styles.css file rather in once single bundle.js file */
plugins: [
new ExtractTextPlugin("styles.css")
],
/* when server is loaded it tells where to look for index file accessed from root */
devServer: {
contentBase: 'public'
},
module: {
preLoaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "jshint-loader"
}
],
loaders: [
{
test: /\.es6$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.css$/,
exclude: /node_modules/ ,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
},
{
test: /\.scss$/,
exclude: /node_modules/ ,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
}
]
},
/* this will resolve file in common js style require without extension */
resolve: {
extensions: ['', '.js', '.es6']
},
watch: true
}
Before using this plugin everything was working fine. As i intend to output different bundle for css, i need to fix this issue.
Found issue in github but it did not help:
https://github.com/webpack/extract-text-webpack-plugin/issues/132
well updating node worked for me. I did this by running "brew update" and "brew upgrade" command, as i am using homebrew as a package manage in mac.
Following instruction in the git link provide in my question resulted in error as i was installing webpack and webpack-dev-server globally. I removed it and only had local copy which did the trick at the end.
command to list global copy of node modules installed:
npm list -g --depth=0
I use this command to remove global copy:
npm uninstall -g {replace_with_package_name}
command to check local copy:
npm list --depth=0