Git Product home page Git Product logo

webpack-sources's Introduction

webpack-sources

Contains multiple classes which represent a Source. A Source can be asked for source code, size, source map and hash.

Source

Base class for all sources.

Public methods

All methods should be considered as expensive as they may need to do computations.

source

Source.prototype.source() -> String | Buffer

Returns the represented source code as string or Buffer (for binary Sources).

buffer

Source.prototype.buffer() -> Buffer

Returns the represented source code as Buffer. Strings are converted to utf-8.

size

Source.prototype.size() -> Number

Returns the size in bytes of the represented source code.

map

Source.prototype.map(options?: Object) -> Object | null

Returns the SourceMap of the represented source code as JSON. May return null if no SourceMap is available.

The options object can contain the following keys:

  • columns: Boolean (default true): If set to false the implementation may omit mappings for columns.

sourceAndMap

Source.prototype.sourceAndMap(options?: Object) -> {
	source: String | Buffer,
	map: Object | null
}

Returns both, source code (like Source.prototype.source() and SourceMap (like Source.prototype.map()). This method could have better performance than calling source() and map() separately.

See map() for options.

updateHash

Source.prototype.updateHash(hash: Hash) -> void

Updates the provided Hash object with the content of the represented source code. (Hash is an object with an update method, which is called with string values)

RawSource

Represents source code without SourceMap.

new RawSource(sourceCode: String | Buffer)

OriginalSource

Represents source code, which is a copy of the original file.

new OriginalSource(
	sourceCode: String | Buffer,
	name: String
)
  • sourceCode: The source code.
  • name: The filename of the original source code.

OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (;, {, }).

SourceMapSource

Represents source code with SourceMap, optionally having an additional SourceMap for the original source.

new SourceMapSource(
	sourceCode: String | Buffer,
	name: String,
	sourceMap: Object | String | Buffer,
	originalSource?: String | Buffer,
	innerSourceMap?: Object | String | Buffer,
	removeOriginalSource?: boolean
)
  • sourceCode: The source code.
  • name: The filename of the original source code.
  • sourceMap: The SourceMap for the source code.
  • originalSource: The source code of the original file. Can be omitted if the sourceMap already contains the original source code.
  • innerSourceMap: The SourceMap for the originalSource/name.
  • removeOriginalSource: Removes the source code for name from the final map, keeping only the deeper mappings for that file.

The SourceMapSource supports "identity" mappings for the innerSourceMap. When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to keep finer mappings from sourceMap.

CachedSource

Decorates a Source and caches returned results of map, source, buffer, size and sourceAndMap in memory. updateHash is not cached. It tries to reused cached results from other methods to avoid calculations, i. e. when source is already cached, calling size will get the size from the cached source, calling sourceAndMap will only call map on the wrapped Source.

new CachedSource(source: Source)
new CachedSource(source: Source | () => Source, cachedData?: CachedData)

Instead of passing a Source object directly one can pass an function that returns a Source object. The function is only called when needed and once.

Public methods

getCachedData()

Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.

original()

Returns the original Source object.

originalLazy()

Returns the original Source object or a function returning these.

PrefixSource

Prefix every line of the decorated Source with a provided string.

new PrefixSource(
	prefix: String,
	source: Source | String | Buffer
)

ConcatSource

Concatenate multiple Sources or strings to a single source.

new ConcatSource(
	...items?: Source | String
)

Public methods

add

ConcatSource.prototype.add(item: Source | String)

Adds an item to the source.

ReplaceSource

Decorates a Source with replacements and insertions of source code.

The ReplaceSource supports "identity" mappings for child source. When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.

Public methods

replace

ReplaceSource.prototype.replace(
	start: Number,
	end: Number,
	replacement: String
)

Replaces chars from start (0-indexed, inclusive) to end (0-indexed, inclusive) with replacement.

Locations represents locations in the original source and are not influenced by other replacements or insertions.

insert

ReplaceSource.prototype.insert(
	pos: Number,
	insertion: String
)

Inserts the insertion before char pos (0-indexed).

Location represents location in the original source and is not influenced by other replacements or insertions.

original

Get decorated Source.

CompatSource

Converts a Source-like object into a real Source object.

Public methods

static from

CompatSource.from(sourceLike: any | Source)

If sourceLike is a real Source it returns it unmodified. Otherwise it returns it wrapped in a CompatSource.

webpack-sources's People

Contributors

ahabhgk avatar alexander-akait avatar andybitz avatar brentwilton avatar dependabot[bot] avatar doniyor2109 avatar edwardbetts avatar elevenpassin avatar evilebottnawi avatar gaearon avatar gnarf avatar jevancc avatar joostk avatar lh0x00 avatar magicduck avatar mattdsteele avatar michael-ciniawsky avatar patrickhulce avatar sokra avatar spacek33z avatar swamp09 avatar thelarkinn avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-sources's Issues

ReplaceSource.js:82 this._source.node is not a function

Hi, i try to start node server, but get below error, it seems .node is undefined.

/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack-sources/lib/ReplaceSource.js:82
                var node = this._source.node(options);
                                        ^

TypeError: this._source.node is not a function
    at ReplaceSource.node (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack-sources/lib/ReplaceSource.js:82:27)
    at proto.sourceAndMap (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack-sources/lib/SourceAndMapMixin.js:29:18)
    at module.exports (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/node_modules/webpack-sources/lib/helpers/streamChunks.js:15:31)
    at ConcatSource.streamChunks (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/node_modules/webpack-sources/lib/ConcatSource.js:113:55)
    at exports.getSourceAndMap (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/node_modules/webpack-sources/lib/helpers/getFromStreamChunks.js:17:33)
    at ConcatSource.sourceAndMap (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/node_modules/webpack-sources/lib/ConcatSource.js:95:10)
    at getTaskForFile (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/SourceMapDevToolPlugin.js:84:30)
    at /Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/SourceMapDevToolPlugin.js:272:22
    at /Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/Cache.js:91:34
    at Array.<anonymous> (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/cache/MemoryCachePlugin.js:45:13)
    at /Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/Cache.js:91:19
    at Hook.eval [as callAsync] (eval at create (/Users/xin/dev/nodejs/OnlineTools/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:19:1)
    at Cache.get (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/Cache.js:75:18)
    at ItemCacheFacade.get (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/CacheFacade.js:111:15)
    at /Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/SourceMapDevToolPlugin.js:223:18
    at arrayEach (/Users/xin/dev/nodejs/OnlineTools/node_modules/neo-async/async.js:2405:9)
    at Object.each (/Users/xin/dev/nodejs/OnlineTools/node_modules/neo-async/async.js:2846:9)
    at /Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/SourceMapDevToolPlugin.js:207:15
    at fn (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/Compilation.js:509:9)
    at _next2 (eval at create (/Users/xin/dev/nodejs/OnlineTools/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at eval (eval at create (/Users/xin/dev/nodejs/OnlineTools/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
    at fn (/Users/xin/dev/nodejs/OnlineTools/node_modules/webpack/lib/Compilation.js:492:9)
    at _next1 (eval at create (/Users/xin/dev/nodejs/OnlineTools/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:21:1)
    at eval (eval at create (/Users/xin/dev/nodejs/OnlineTools/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:37:1)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.12.1

The package.json file contains:

"dependencies": {
    "@marko/build": "^4.2.5",
    "chromedriver": "^107.0.3",
    "compression": "^1.7.4",
    "express": "^4.17.1",
    "jquery": "^3.5.1",
    "marked": "^4.2.3",
    "purecss": "^3.0.0",
    "raptor-pubsub": "^1.0.5",
    "raptor-util": "^3.1.0",
    "serve-static": "^1.14.1",
    "source-map": "^0.7.4",
    "source-map-support": "^0.5.21",
    "sourcemap-validator": "^2.1.0",
    "whatwg-fetch": "^3.0.0",
    "yasm": "^0.1.2"
  },
  "devDependencies": {
    "@marko/webpack": "^9.3.0",
    "clean-webpack-plugin": "^4.0.0",
    "css-loader": "^6.7.2",
    "css-minimizer-webpack-plugin": "^4.2.2",
    "file-loader": "^6.2.0",
    "ignore-emit-webpack-plugin": "^2.0.2",
    "less": "^4.1.3",
    "less-loader": "^11.1.0",
    "marko": "^5.22.0",
    "marko-cli": "^7.1.0",
    "mini-css-extract-plugin": "^2.7.0",
    "spawn-server-webpack-plugin": "^6.2.2",
    "svg-url-loader": "^8.0.0",
    "webpack": "^5.75.0",
    "webpack-cli": "^5.0.0",
    "webpack-dev-server": "^4.11.1"
  }

I wan replace some string in the code

code: xx.js
source: abcdedfg, ../images/xx.png ....

i want replace the '../images/xx.png' to 'images/xx.png'

compilation.assets[file] = new ReplaceSource(
newCode
)

npm run build:
/node_modules/webpack-sources/lib/ReplaceSource.js:35
return this._replaceString(this._source.source());

TypeError: this._source.source is not a function

Error: "." is not in the SourceMap [email protected]

Hi, we found that [email protected] cause this error, however [email protected] is ok.

the detail errors is listed bellow.

/cloud/source_code/node_modules/_source-map@0.6.1@source-map/lib/source-map-consumer.js:753
throw new Error('"' + relativeSource + '" is not in the SourceMap.');
^
Error: "." is not in the SourceMap.
at BasicSourceMapConsumer.SourceMapConsumer_sourceContentFor [as sourceContentFor] (/cloud/source_code/node_modules/_source-map@0.6.1@source-map/lib/source-map-consumer.js:753:13)
at /cloud/source_code/node_modules/_webpack-sources@1.4.0@webpack-sources/lib/applySourceMap.js:88:47

HookWebpackError: item.node is not a function

I am setting up a new project with the latest and greatest of all tools, and ran into the following situation:

I am using:

[email protected]
webpack-cli@next
[email protected]

webpack.config.js

plugins: [
    new WrapperPlugin({
        header: () => fs.readFileSync(path.resolve(__dirname, 'shim.js'), 'utf8'),
    }),
]

[email protected]

webpack.config.js

minimizer: [
    new TerserPlugin({
        terserOptions: {
            compress: {
                collapse_vars: false,
                conditionals: false,
                comparisons: false,
            },
            output: {
                comments: false,
            },
        },
    }),
],

(Yarn 2 with loose mode enabled)

Now, when I debug the error (has to be on Node 13+, to make it work with Yarn 2's PnP, I used node 14):

package.json

"debug": "node --inspect --inspect-brk=5858 $(yarn bin webpack) --config webpack.config.js"

I get this:

Screenshot 2020-10-15 at 15 59 49

So it looks like the CachedSource is missing the node function.
The other possibility is that the CachedSource is not an allowed child for ConcatSource, so i'll move up the call stack to where the children are coming from and end up over here:

Screenshot 2020-10-15 at 16 02 14

I added a breakpoint to indicate the line where the children are coming from.

They are coming from webpack's compilation.getAsset('outfile.js').source.

The source is a ConcatSource, containing 3 children

  1. A string with the header coming from the WrapperPlugin
  2. The (offending?) CachedSource, which contains webpack runtime code under _source(which is a ConcatSource)._children
  3. An empty string (not sure where this comes from)

I am not sure what is right and what is wrong, so I am asking for a pointer in the right direction.

I'd be glad to send a PR, but I guess I need some help since I am not sure what should happen.

ng build success but throwing error on ng serve -- return new error

I am getting the below issue in my angular project on ng serve but ng build is successful.

I have done the below trials to resolve the error
trial 1: Removed the .angular folder and node modules folder and tried to install the modules again but no luck.
trial 2: removed the angular and node packages and tried to install again but got same error.

Error :
node_modules\webpack-sources\lib\SizeOnlySource.js:16
return new Error(
^

Error: Content and Map of this Source is not available (only size() is supported)
at SizeOnlySource._error (node_modules\webpack-sources\lib\SizeOnlySource.js:16:10)
at SizeOnlySource.buffer (node_modules\webpack-sources\lib\SizeOnlySource.js:30:14)
at _isSourceEqual (node_modules\webpack\lib\util\source.js:21:51)
at isSourceEqual (node_modules\webpack\lib\util\source.js:43:17)
at Compilation.emitAsset (node_modules\webpack\lib\Compilation.js:4215:9)
at node_modules\webpack\lib\Compiler.js:553:28
at node_modules\webpack\lib\Compiler.js:1183:17
at eval (eval at create (node_modules\tapable\lib\HookCodeFactory.js:33:10), :13:1)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)

applySourceMap for webpack 4 is super slow

for(var i = 0; i < m2rMappings.length; i++) {
if(m2rMappings[i].generatedColumn <= middleMapping.column) {
m2rBestFit = m2rMappings[i];
}
}

Webpack 4 is still using the 1.4.1 version of webpack-sources, in which version these lines are super slow, especially for those files whose lines are very long.

I came across this problem when my webpack 4 trying to load exceljs (which actually loads exceljs.min.js, an already minified file that has very long lines) and generate a sourcemap with columns.

Maybe excluding dependencies like these files is the best practice, but I assume that this should be optimized.

Error: "." is not in the SourceMap.

Description

Getting the following build error: Error: "." is not in the SourceMap

Full error stack:

โžœ  webpack-sources-repro git:(master) npm run build

> [email protected] build /webpack-sources-repro
> webpack --config webpack.config

(node:95967) UnhandledPromiseRejectionWarning: Error: "." is not in the SourceMap.
    at BasicSourceMapConsumer.SourceMapConsumer_sourceContentFor [as sourceContentFor] (/webpack-sources-repro/node_modules/webpack-sources/node_modules/source-map/lib/source-map-consumer.js:753:13)
    at /webpack-sources-repro/node_modules/webpack-sources/lib/applySourceMap.js:144:46
    at SourceNode_walk [as walk] (/webpack-sources-repro/node_modules/webpack-sources/node_modules/source-map/lib/source-node.js:230:9)
    at SourceNode_walk [as walk] (/webpack-sources-repro/node_modules/webpack-sources/node_modules/source-map/lib/source-node.js:226:13)
    at applySourceMap (/webpack-sources-repro/node_modules/webpack-sources/lib/applySourceMap.js:58:13)
    at SourceMapSource.node (/webpack-sources-repro/node_modules/webpack-sources/lib/SourceMapSource.js:198:11)
    at exports.getSourceAndMap (/webpack-sources-repro/node_modules/webpack-sources/lib/helpers.js:17:21)
    at SourceMapSource.sourceAndMap (/webpack-sources-repro/node_modules/webpack-sources/lib/SourceMapSource.js:184:10)
    at getTaskForFile (/webpack-sources-repro/node_modules/webpack/lib/SourceMapDevToolPlugin.js:65:30)
    at /webpack-sources-repro/node_modules/webpack/lib/SourceMapDevToolPlugin.js:215:20
    at Array.forEach (<anonymous>)
    at /webpack-sources-repro/node_modules/webpack/lib/SourceMapDevToolPlugin.js:186:12
    at SyncHook.eval [as call] (eval at create (/webpack-sources-repro/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:5:1)
    at SyncHook.lazyCompileHook (/webpack-sources-repro/node_modules/tapable/lib/Hook.js:154:20)
    at /webpack-sources-repro/node_modules/webpack/lib/Compilation.js:1413:42
    at eval (eval at create (/webpack-sources-repro/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:95967) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:95967) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Version

v2.0.0
(Potentially v1.4.0?)

Related issues

#55

Reproduction

https://github.com/privatenumber/webpack-sources-bug-repro

  • The bug seems to happen with output.libraryTarget: 'umd'. Works fine when removing that line.

  • The repro isn't as minimal as it could be, but I'm the maintainer of esbuild-loader and that's what I'm using to reproduce this. Let me know if you'd like to trim it down even more.

ConcatSource.js:42 failing with Cannot read property 'source' of undefined

I'm not sure how to report this since I don't know if this is a bug or just that I am not understanding how to use webpack 5

I am trying to follow the nextjs webpack5 module-federation example here: https://github.com/module-federation/module-federation-examples/tree/master/nextjs

I am incorporating this into my own project, so i am using just the next.config.js file from that example and some things from the package.json

when i try to run yarn dev i get the below output

if i change

source += typeof child === "string" ? child : child.source();
to

source += typeof child === "string" ? child : null;
im able to run the application but i have no idea what the repercussions of that change will be since i have no idea what this code does.

โฏ yarn dev
yarn run v1.22.10
$ run-p api-mock next
$ node api-mock.js
$ next --port 3002
Processed 13 unique mocks.
Processed 0 unique presets.
Mock API listening on port 9500
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
ready - started server on http://localhost:3002
(node:3395) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(Use `node --trace-deprecation ...` to show where the warning was created)
/Users/jdryhurs/work/skyline-federation/next1/node_modules/webpack-sources/lib/ConcatSource.js:42
                        source += typeof child === "string" ? child : child.source();
                                                                            ^

TypeError: Cannot read property 'source' of undefined
    at ConcatSource.source (/Users/jdryhurs/work/skyline-federation/next1/node_modules/webpack-sources/lib/ConcatSource.js:42:56)
    at getContent (/Users/jdryhurs/work/skyline-federation/next1/node_modules/webpack/lib/Compiler.js:629:39)
    at processMissingFile (/Users/jdryhurs/work/skyline-federation/next1/node_modules/webpack/lib/Compiler.js:745:24)
    at /Users/jdryhurs/work/skyline-federation/next1/node_modules/webpack/lib/Compiler.js:785:10
    at callback (/Users/jdryhurs/work/skyline-federation/next1/node_modules/graceful-fs/polyfills.js:295:20)
    at FSReqCallback.oncomplete (node:fs:199:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "next" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expand Webpack's benchmark tests to measure webpack-sources perf

Since there is now a benchmarking test suite for webpack, I think it would be useful to be able to measure performance improvements in webpack-sources too. Since it is a separate package I think changes to webpack-sources will affect all the measurements in the main benchmark and it will therefore not show any performance differences.

For huge bundles, webpack-sources has to do a lot of work and any improvements here will most likely strongly impact the performance of webpack in general.

TypeError: value.split is not a function

I am going to setup my own scaffold๏ผŒand here is the project repo

https://github.com/Kilims/typescript_antd_antdMobile

while running with yarn run start, it could work perfectly

but when i go with yarn run build, it shows errors below

TypeError: value.split is not a function
    at OriginalSource.node (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/webpack-sources/lib/OriginalSource.js:34:21)
    at /Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/webpack-sources/lib/ConcatSource.js:59:50
    at Array.map (<anonymous>)
    at ConcatSource.node (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/webpack-sources/lib/ConcatSource.js:58:63)
    at ConcatSource.proto.sourceAndMap (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/webpack-sources/lib/SourceAndMapMixin.js:29:18)
    at CachedSource.sourceAndMap (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/webpack-sources/lib/CachedSource.js:58:31)
    at OptimizeCssAssetsWebpackPlugin.processCss (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/optimize-css-assets-webpack-plugin/src/index.js:44:44)
    at Object.processor (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/optimize-css-assets-webpack-plugin/src/index.js:13:18)
    at /Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/last-call-webpack-plugin/src/index.js:150:10
    at arrayEach (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/lodash/_arrayEach.js:15:9)
    at forEach (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/lodash/forEach.js:38:10)
    at OptimizeCssAssetsWebpackPlugin.process (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/last-call-webpack-plugin/src/index.js:147:5)
    at /Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/last-call-webpack-plugin/src/index.js:178:28
    at _next0 (eval at create (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:17)
    at eval (eval at create (/Users/yejinlei/Documents/playground/personal/typescript/my-app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)

could kindly help with that ? tons of thanks

[question] why ReplaceSource.map.sourcesContent not change

Hi,
ReplaceSource test case show expect(resultText).toBe("Hi bye W0000rld!\n{\n Multi Line\n}\nLast Line"); L49 result changed
but resultMap.map.sourcesContent๏ผŒresultListMap.map.sourcesContent is also the originalText.
the print code console.log("resultMap.map.sourcesContent: ", resultMap.map.sourcesContent); show
console.log resultMap.map.sourcesContent: [ 'Hello World!\n{}\nLine 3\nLine 4\nLine 5\nLast\nLine' ]
Why result changed by sourcesContent not change ?

Thx!

Source.Replace can't replace all

code


class MyDependency extends Dependency {
  // Use the constructor to save any information you need for later
  constructor(module) {
    super();
    this.module = module;
  }
}

MyDependency.Template = class MyDependencyTemplate {
  apply(dep, source) {
    // dep is the MyDependency instance, so the module is dep.module
    source.replace(0, source.source().length - 1, source.source() )
  }
};

module.exports = class MyPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap('MyPluginName', compilation => {
      compilation.dependencyTemplates.set(
        MyDependency,
        new MyDependency.Template()
      );
      compilation.hooks.buildModule.tap('MyPluginName', module => {
        module.addDependency(new MyDependency(module));
      });
    });
  }
};

i want to replace "source" through babel๏ผŒ
but I only use the replace to replace all will report an error.
I feel that this should be Sourcemap.

Refactor: Convert the existing code to Idiomatic ES6

I would like to refactor the code base wherever possible so that we are using the latest ES6 syntax.
One example from the source would be:
Turning this

if(source.node) this.node = function(options) {
			return this._source.node(options);
		};

into

if(source.node) this.node = (options) => this._source.node(options);

This sort of code would decrease verbosity and helps contributors to write efficient and better code. At some places, I will be using Lebab, a codemod for changing ES5 to ES6 code. Would like to know your thoughts.

How to replace the RawSource's value ?

I wtite a webpack plugin to compress image. For example there is an img's rawSource instance:

RawSource {
  _value:
   <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 65 00 00 00 de 08 06 00 00 00 24 71 ce 79 00 00 20 00 49 44 41 54 78 9c ed bd 07 98 1c d5 95 ... >,
  existsAt:
   'E:\\git\\tinyimg-webpack-plugin\\test\\dist\\images\\logo.d8d2.png',
  emitted: true }

After compressing the img , I want to repalce the the origin img by new img:

myRawSource._value = 'new img binary content';

but, it doesn't work.

I have to use fs.writeFile() to make it work as follows:

fs.wirteFile(myRawSource.existsAt, 'new img binary content', 'binary');

Can any body tell me whether there is a better solution ?

UnhandledPromiseRejectionWarning: Error: "." is not in the SourceMap (reproducible)

@evilebottnawi Ok, I've finally created a reproducible test repo (as requested in #55). I forked HashemKhalifa/webpack-react-boilerplate and the ONLY things I changed were:

  • upgrading to webpack@5 RC
  • setting babel preset-env to use targets: 'defaults'

Here is the repo: https://github.com/dlong500/webpack-react-boilerplate/tree/source-map-diag
The changes are in the source-map-diag branch.

Building the project via yarn run build (or npm) yields the following:
source-map-diag

please update source-map to 0.7

With source-map 0.7, two tests are failing.

mocha -R spec


  ConcatSource
    โœ“ should concat two sources
    โœ“ should be able to handle strings for all methods

  PrefixSource
    โœ“ should prefix a source
    โœ“ should have consistent source/sourceAndMap behavior

  ReplaceSource
    1) should replace correctly
    2) should replace multiple items correctly

  package-entry
    โœ“ should not throw SyntaxError


  5 passing (68ms)
  2 failing

  1) ReplaceSource
       should replace correctly:
     TypeError: (intermediate value).originalPositionFor is not a function
      at ReplaceSource._replacementToSourceNode (lib/ReplaceSource.js:156:54)
      at ReplaceSource.<anonymous> (lib/ReplaceSource.js:83:37)
      at Array.forEach (<anonymous>)
      at ReplaceSource.node (lib/ReplaceSource.js:76:21)
      at ReplaceSource.proto.sourceAndMap (lib/SourceAndMapMixin.js:30:18)
      at Context.<anonymous> (test/ReplaceSource.js:31:26)
      at callFn (/usr/lib/nodejs/mocha/lib/runnable.js:354:21)
      at Test.Runnable.run (/usr/lib/nodejs/mocha/lib/runnable.js:346:7)
      at Runner.runTest (/usr/lib/nodejs/mocha/lib/runner.js:442:10)
      at /usr/lib/nodejs/mocha/lib/runner.js:560:12
      at next (/usr/lib/nodejs/mocha/lib/runner.js:356:14)
      at /usr/lib/nodejs/mocha/lib/runner.js:366:7
      at next (/usr/lib/nodejs/mocha/lib/runner.js:290:14)
      at Immediate.<anonymous> (/usr/lib/nodejs/mocha/lib/runner.js:334:5)

  2) ReplaceSource
       should replace multiple items correctly:
     TypeError: (intermediate value).originalPositionFor is not a function
      at ReplaceSource._replacementToSourceNode (lib/ReplaceSource.js:156:54)
      at ReplaceSource.<anonymous> (lib/ReplaceSource.js:83:37)
      at Array.forEach (<anonymous>)
      at ReplaceSource.node (lib/ReplaceSource.js:76:21)
      at ReplaceSource.proto.sourceAndMap (lib/SourceAndMapMixin.js:30:18)
      at Context.<anonymous> (test/ReplaceSource.js:61:26)
      at callFn (/usr/lib/nodejs/mocha/lib/runnable.js:354:21)
      at Test.Runnable.run (/usr/lib/nodejs/mocha/lib/runnable.js:346:7)
      at Runner.runTest (/usr/lib/nodejs/mocha/lib/runner.js:442:10)
      at /usr/lib/nodejs/mocha/lib/runner.js:560:12
      at next (/usr/lib/nodejs/mocha/lib/runner.js:356:14)
      at /usr/lib/nodejs/mocha/lib/runner.js:366:7
      at next (/usr/lib/nodejs/mocha/lib/runner.js:290:14)
      at Immediate.<anonymous> (/usr/lib/nodejs/mocha/lib/runner.js:334:5)

Update to source-map 0.6.1 causes an error when running Webpack

This update seems to create another issue (this is also reported here):

frontend/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:276
        throw new Error(
        ^

Error: original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.
    at SourceMapGenerator_validateMapping [as _validateMapping] (frontend/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:276:15)
    at SourceMapGenerator_addMapping [as addMapping] (frontend/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:110:12)
    at frontend/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:72:17
    at Array.forEach (<anonymous>)
    at BasicSourceMapConsumer.SourceMapConsumer_eachMapping [as eachMapping] (frontend/node_modules/webpack-sources/node_modules/source-map/lib/source-map-consumer.js:157:14)
    at Function.SourceMapGenerator_fromSourceMap [as fromSourceMap] (frontend/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:48:24)
    at SourceMapSource.node (frontend/node_modules/webpack-sources/lib/SourceMapSource.js:32:35)
    at SourceMapSource.proto.sourceAndMap (frontend/node_modules/webpack-sources/lib/SourceAndMapMixin.js:30:18)
    at getTaskForFile (frontend/node_modules/webpack/lib/SourceMapDevToolPlugin.js:33:30)
    at chunk.files.forEach.file (frontend/node_modules/webpack/lib/SourceMapDevToolPlugin.js:91:21)

Reverting to v1.0.1 resolves this issue.

res.code is generated code and not Source.prototype.source()

source = res.code;

Documents write:

sourceAndMap
Source.prototype.sourceAndMap(options?: Object) -> {
	source: String | Buffer,
	map: Object | null
}
Returns both, source code (like Source.prototype.source() and SourceMap (like Source.prototype.map()). This method could have better performance than calling source() and map() separately.

See map() for options.

Can you explain it ? thx

remove unnecessary memory allocation from ConcatSource and ReplaceSource

The code in ConcatSource::source() and ReplaceSource::_replaceString() is using array.join("") which causes allocation of new strings. Using simple concatenation with += instead causes node to create what it calls something like "concatenated strings" internally which reuse the memory of the original strings being concatenated (this is probably possible since strings are immutable).

This problem was discovered by recording a "memory allocation profile" using chrome dev tools for the duration of the whole webpack build.

Before:
image

After change:
image

why sourceAndMap columns: false is different with columns: true

Hi,
I understand 'AAAA;;AAEA'
don't understand why columns: true mappings is "AAAA;AACA;AACA;". The second line is no content

describe("OriginalSource", () => {
	it("should handle multiline string", () => {
		const source = new OriginalSource("Line1\n\nLine3\n", "file.js");
		const resultText = source.source();
		const resultMap = source.sourceAndMap({
			columns: true
		});
		const resultListMap = source.sourceAndMap({
			columns: false
		});

		expect(resultText).toBe("Line1\n\nLine3\n");
		expect(resultMap.source).toEqual(resultText);
		expect(resultListMap.source).toEqual(resultText);
		expect(resultListMap.map.file).toEqual(resultMap.map.file);
		expect(resultListMap.map.version).toEqual(resultMap.map.version);
		expect(resultMap.map.sources).toEqual(["file.js"]);
		expect(resultListMap.map.sources).toEqual(resultMap.map.sources);
		expect(resultMap.map.sourcesContent).toEqual(["Line1\n\nLine3\n"]);
		expect(resultListMap.map.sourcesContent).toEqual(
			resultMap.map.sourcesContent
		);
		expect(resultMap.map.mappings).toBe("AAAA;;AAEA");
		expect(resultListMap.map.mappings).toBe("AAAA;AACA;AACA;");
	});

Could someone help me ? Thx

Build prod in ionic project results in heap out of memory

Guys, the new version of webpack-source 1.2.0 completely screw up my ionic project build!

[13:44:05] webpack started ...
[13:44:23] copy finished in 44.53 s

Fatal error in , line 0

API fatal error handler returned after process out of memory

==== C stack trace ===============================

ionic(v8::base::debug::StackTrace::StackTrace()+0x16) [0x15c8c36]
ionic() [0x1451857]
ionic(V8_Fatal+0xd8) [0x15c3998]
ionic(v8::internal::V8::FatalProcessOutOfMemory(char const*, bool)+0x1fc) [0xb9103c]
ionic(v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*)+0x504) [0xfff764]
ionic(bool v8::internal::LiveObjectVisitor::VisitBlackObjects<v8::internal::EvacuateNewSpaceVisitor>(v8::internal::MemoryChunk*, v8::internal::MarkingState const&, v8::internal::EvacuateNewSpaceVisitor*, v8::internal::LiveObjectVisitor::IterationMode)+0x7b) [0x100149b]
ionic(v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::Page*, long*)+0x490) [0x10021d0]
ionic(v8::internal::Evacuator::EvacuatePage(v8::internal::Page*)+0x51) [0xfeb1b1]
ionic(v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal()+0xac) [0xfeb34c]
ionic(v8::internal::CancelableTask::Run()+0x36) [0xc75146]
ionic(v8::platform::WorkerThread::Run()+0x19) [0x1459149]
ionic() [0x15c9ce0]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba) [0x7fe3418c16ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fe3415f741d]

Only get fixed when I rolledback version to 1.1.0. But it was hard do find once that dependency is applied by the Uglify command. Others projects might be passing by the same problems

webpack-sources' Source type is not assigneable to webpack5 source type

Code sample

    const fileAsset = compilation.assets[fileName];
    const source = new ReplaceSource(fileAsset);

TS Compilation Error

 Argument of type 'Source' is not assignable to parameter of type 'import("<path>/@types/webpack-sources/lib/Source")'.
  The types returned by 'map(...)' are incompatible between these types.
    The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
      Type 'Object' is missing the following properties from type 'RawSourceMap': version, sources, names, mappings, file

52         const source = new ReplaceSource(fileAsset);

[email protected] Source type

declare class Source {
	constructor();
	size(): number;
	map(options: MapOptions): Object;
	sourceAndMap(options: MapOptions): { source: string | Buffer; map: Object };
	updateHash(hash: Hash): void;
	source(): string | Buffer;
	buffer(): Buffer;
}

@types/[email protected] Source type

declare abstract class Source {
    source(): string | ArrayBuffer;
    buffer(): Buffer;
    size(): number;
    map(options?: MapOptions): RawSourceMap | null;
    sourceAndMap(options?: MapOptions): SourceAndMapResult;
    updateHash(hash: Hash): void;
}
map(options: MapOptions): Object; vs map(options?: MapOptions): RawSourceMap | null;

Expectation from my side they should be corresponding to the same type as a part of single ecosystem

Sources whose source() return strings do not have the correct size() if it contains unicode

Strings returned by source() that have unicode characters outside of the ascii range have lengths that are not the number of bytes of the string but the number of unicode characters in the string. The number of bytes could be computer by casting the string to a Buffer whose length will be the number of bytes or other possible ways.

As it is, webpack features and plugins that depend on an accurate size value to produce some output or reflect some information are likely to not work as expected.

Should add an explicit license

I would guess that you guys intended to license this with the same MIT licenses you do most of your projects. However, the fact that one is not explicitly posted opens up questions as to intent.

It would be a good idea to add an explicit license to be clear to consumers your and their freedoms.

last version webpack-sources consuming [email protected]

$ npm install [email protected]
npm ERR! code ETARGET
npm ERR! notarget No matching version found for source-map@~0.6.1.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'webpack-sources'
npm ERR! notarget

It prevents me from creating new angular applications
Here paste my stack overflow post
https://es.stackoverflow.com/questions/304557/creating-new-angular-application

Using listMap returns a completely broken source map

I have been having some major issues getting webpack to generate valid source maps in dev mode (Also in prod, though I haven't started looking at that yet). In the end I was able to isolate this issue down to here.

It appears webpack is generating Source objects, as per the following example (Formatted for convenience):

debug> exec console.dir(this, {depth: 10})

ReplaceSource {
  _source: 
   SourceMapSource {
     _value: 'Object.defineProperty(exports,"__esModule",{value:true});var _jsxFileName="/home/tiki/path/to/project/src/components/BugExample.js"; \
              var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable= \
              descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor); \
              }}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps); \
              return Constructor;};}();var _react=require("react");var _react2=_interopRequireDefault(_react);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}; \
              }function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var BugExample=function(){ \
              function BugExample(){_classCallCheck(this,BugExample);}_createClass(BugExample,[{key:"someExampleFunction",value:function someExampleFunction(){console.log("I do fancy stuff"); \
              }},{key:"anotherExampleFunction",value:function anotherExampleFunction(){console.log("I do other stuff");return _react2.default.createElement("div",{__source: \
              {fileName:_jsxFileName,lineNumber:11}},"Woo");}}]);return BugExample;}();exports.default=BugExample;',
     _name: '/home/tiki/path/to/project/node_modules/babel-loader/lib/index.js??ref--0!/home/tiki/path/to/project/src/components/BugExample.js',
     _sourceMap: 
      { version: 3,
        sources: [ 'src/components/BugExample.js' ],
        names: [ 'BugExample', 'console', 'log' ],
        mappings: 'iqBAAA,4B,kRAEMA,W,4JACkB,CACpBC,QAAQC,GAAR,CAAY,kBAAZ,EACD,C,uEAEwB,CACvBD,QAAQC,GAAR,CAAY,kBAAZ,EACA,MACE,4FADF,CAGD,C,0CAGYF,U',
        file: 'BugExample.js',
        sourceRoot: '/home/tiki/path/to/project',
        sourcesContent: [ 'import React, { Component } from "react"\n\nclass BugExample {\n  someExampleFunction() {\n    console.log("I do fancy stuff")\n  }\n\n  anotherExampleFunction() \
                           {\n    console.log("I do other stuff")\n    return (\n      <div>Woo</div>\n    )\n  }\n}\n\nexport default BugExample\n' ] },
     _originalSource: undefined,
     _innerSourceMap: undefined },
  _name: undefined,
  replacements: 
   [ [ 692, 698, '/*! react */ 2', 0 ],
     [ 684, 690, '__webpack_require__', 1 ] ] }

When I call listMap on the above object (this happens when options.module is either true or false), the resulting source map doesn't map anything (neither line numbers nor columns), as follows:

debug> exec console.dir(this.listMap(options).toStringWithSourceMap({file: "x"}), {depth: 10})

{ source: '// ... Same as above ...',
  map: 
   { version: 3,
     file: 'x',
     sources: [ 'src/components/BugExample.js' ],
     sourcesContent: [ 'import React, { Component } from "react"\n\nclass BugExample {\n  someExampleFunction() {\n    console.log("I do fancy stuff")\n  }\n\n  anotherExampleFunction() {\n    console.log("I do other stuff")\n    return (\n      <div>Woo</div>\n    )\n  }\n}\n\nexport default BugExample\n' ],
     mappings: 'AAAA' } }

This doesn't seem to affect the other code path (when options.columns is true), as follows:

debug> exec console.dir(this.node(options).toStringWithSourceMap({file: "x"}).map.toJSON(), {depth: 10})

{ version: 3,
  sources: [ '/home/tiki/path/to/project/src/components/BugExample.js' ],
  names: [ 'BugExample', 'console', 'log' ],
  mappings: 'iqBAAA,+C,kRAEMA,W,4JACkB,CACpBC,QAAQC,GAAR,CAAY,kBAAZ,EACD,C,uEAEwB,CACvBD,QAAQC,GAAR,CAAY,kBAAZ,EACA,MACE,4FADF,CAGD,C,0CAGYF,U',
  file: 'x',
  sourcesContent: [ 'import React, { Component } from "react"\n\nclass BugExample {\n  someExampleFunction() {\n    console.log("I do fancy stuff")\n  }\n\n  anotherExampleFunction() {\n    console.log("I do other stuff")\n    return (\n      <div>Woo</div>\n    )\n  }\n}\n\nexport default BugExample\n' ] }

If this is expected behavior, then webpack devtool docs should be updated to reflect the fact that line numbers are not correctly mapped.

PrefixSource bug: source() !== sourceAndMap().source

empty lines are not handled consistently which breaks ReplaceSource indices that might be based on a particular version of the source.

Example
Prefix: foobar
Nodes: ["console.log(1);\n", "\n", "console.log(2);\n"]

source() -> foobar console.log(1);\n\nfoobar console.log(2);\n
sourceAndMap().source -> foobar console.log(1);\nfoobar \nfoobar console.log(2);\n

Improve performance of `node` method in `ReplaceSources`

This is related to this issue: webpack-contrib/uglifyjs-webpack-plugin#161

I have a huge code base with thousands of files, and after several hours of trying to figure out with uglify-js was slow when enabling sourcemaps. I ended up looking into this library and it's source.

I noticed that node method in ReplaceSources takes a lot of time to execute, infact if I disable columns from map() the it improves the speed by at least 40 minutes.

https://github.com/webpack/webpack-sources/blob/master/lib/ReplaceSource.js#L68

consider using krisselden/fast-source-map or something like it

Do you want to request a feature or report a bug?
feature

What is the current behavior?
source-map library is antequated and slow + consumes tons of memory.

If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
fast sourcemaps

If this is a feature request, what is motivation or use case for changing the behavior?
For larger projects, sourcemap generation is really a large chunk of the total time webpack spends compiling. Having faster sourcemap generation would help with faster builds/incremental builds.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

The library here seems like an interesting alternative:
https://github.com/krisselden/fast-source-map
According to their benchmarks, they are 10x faster than source-map.


This issue was moved from webpack/webpack#5171 by @sokra. Orginal issue was by @MagicDuck.

Error: "." is not in the SourceMap. still in 1.4.1

Similar to #55, but not fixed for me in 1.4.1, I get this when building:

$ NODE_ENV=production wp
Error: "." is not in the SourceMap.
    at BasicSourceMapConsumer.SourceMapConsumer_sourceContentFor [as sourceContentFor] (/Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/source-map/lib/source-map-consumer.js:753:13)
    at /Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/webpack-sources/lib/applySourceMap.js:88:47
    at SourceNode_walk [as walk] (/Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/source-map/lib/source-node.js:230:9)
    at SourceNode_walk [as walk] (/Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/source-map/lib/source-node.js:226:13)
    at applySourceMap (/Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/webpack-sources/lib/applySourceMap.js:58:13)
    at SourceMapSource.node (/Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/webpack-sources/lib/SourceMapSource.js:36:11)
    at SourceMapSource.proto.sourceAndMap (/Users/user/Source/project/client/node_modules/terser-webpack-plugin/node_modules/webpack-sources/lib/SourceAndMapMixin.js:29:18)
    at getTaskForFile (/Users/user/Source/project/node_modules/webpack/lib/SourceMapDevToolPlugin.js:64:30)
    at files.forEach (/Users/user/Source/project/node_modules/webpack/lib/SourceMapDevToolPlugin.js:200:20)
    at Array.forEach (<anonymous>)
    at compilation.hooks.afterOptimizeChunkAssets.tap (/Users/user/Source/project/node_modules/webpack/lib/SourceMapDevToolPlugin.js:177:12)
    at SyncHook.eval [as call] (eval at create (/Users/user/Source/project/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (/Users/user/Source/project/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeChunkAssets.callAsync.err (/Users/user/Source/project/node_modules/webpack/lib/Compilation.js:1385:42)
    at _promise1.then._result1 (eval at create (/Users/user/Source/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)

"Maximum call stack size exceeded" in streamChunks*

Using storybook with webpack5 we recently ended up getting "Maximum call stack size exceeded" when we try to build the storybook project.

    RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at streamChunksOfRawSource (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfRawSource.js:14:25)
    at module.exports (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfRawSource.js:40:5)
    at RawSource.streamChunks (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\RawSource.js:56:10)
    at module.exports (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunks.js:13:17)
    at streamAndGetSourceAndMap (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamAndGetSourceAndMap.js:27:53)
    at CachedSource.streamChunks (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\CachedSource.js:208:35)
    at module.exports (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunks.js:13:17)
    at ReplaceSource.streamChunks (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\ReplaceSource.js:176:44)
    at module.exports (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunks.js:13:17)
    at ConcatSource.streamChunks (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\ConcatSource.js:112:55)
    at module.exports (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunks.js:13:17)
    at streamAndGetSourceAndMap (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamAndGetSourceAndMap.js:27:53)
    at CachedSource.streamChunks (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\CachedSource.js:208:35)
    at module.exports (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunks.js:13:17)
    at ConcatSource.streamChunks (C:\src\node_modules\webpack\node_modules\webpack-sources\lib\ConcatSource.js:112:55)

It seems to be caused by the regex used for the match. I have seen it in two different spots. The other one was:

UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at streamChunksOfSourceMapLinesFull (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfSourceMap.js:167:23)
    at module.exports (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfSourceMap.js:405:6)
    at nameIndexMapping.<computed> (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfCombinedSourceMap.js:271:5)
    at streamChunksOfSourceMapLinesFinal (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfSourceMap.js:331:3)
    at module.exports (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfSourceMap.js:398:6)
    at streamChunksOfCombinedSourceMap (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\streamChunksOfCombinedSourceMap.js:54:9)
    at SourceMapSource.streamChunks (\node_modules\webpack\node_modules\webpack-sources\lib\SourceMapSource.js:197:11)
    at exports.getSourceAndMap (\node_modules\webpack\node_modules\webpack-sources\lib\helpers\getFromStreamChunks.js:17:33)
    at SourceMapSource.sourceAndMap (\node_modules\webpack\node_modules\webpack-sources\lib\SourceMapSource.js:188:10)
    at getTaskForFile (\node_modules\webpack\lib\SourceMapDevToolPlugin.js:84:30)
    at \node_modules\webpack\lib\SourceMapDevToolPlugin.js:272:22
    at \node_modules\webpack\lib\Cache.js:93:5
    at Hook.eval [as callAsync] (eval at create (\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Cache.get (\node_modules\webpack\lib\Cache.js:75:18)
    at ItemCacheFacade.get (\node_modules\webpack\lib\CacheFacade.js:117:15)

At first I thought it might be cause of a big chunk and source file but I tried to output "source" prior to the "source.match" and it seems to only contain:

/* module decorator */ module = __webpack_require__.hmd(module);\n

I'm not sure how to create a reproducable way for that issues however it vanishes when downgrading to webpack ~5.46.0 and whenever I upgrade back to ~5.47.0 the error reappears.

Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Getting this error continously after upgrading the package to 1.4.1. No issues were observed in 1.3.0

applySourceMap.js file was added recently. what is going wrong here ?

<--- JS stacktrace --->

==== JS stack trace =========================================

0: ExitFrame [pc: 0xb41561dbe1d]
1: StubFrame [pc: 0xb41561a0573]

Security context: 0x353fb8d9e6e9
2: /* anonymous /(aka / anonymous */) [0x115ab165d461] [/node_modules/webpack-sources/lib/applySourceMap.js:~58] [pc=0xb41578f5e0d](this=0x2729fd7826f1 ,c...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x8dc510 node::Abort() [node]
2: 0x8dc55c [node]
3: 0xad9b5e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xad9d94 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xec7bf2 [node]
6: 0xec7cf8 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
7: 0xed3dd2 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xed4704 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xed7371 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
10: 0xea6fbb v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
11: 0xff08b3 v8::internal::String::SlowFlatten(v8::internal::Handlev8::internal::ConsString, v8::internal::PretenureFlag) [node]
12: 0xad7184 v8::internal::String::Flatten(v8::internal::Handlev8::internal::String, v8::internal::PretenureFlag) [node]
13: 0xff1a1e v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handlev8::internal::String) [node]
14: 0x1169f18 v8::internal::Runtime_HasProperty(int, v8::internal::Object**, v8::internal::Isolate*) [node]
15: 0xb41561dbe1d
npm ERR! code ELIFECYCLE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.