-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Cannot assign to read only property 'exports' of object '#<Object>' (mix require and export) #4039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The code above is ok. You can mix |
@sokra probably in real code I had something more, that caused the issue. Now I've refactored this part to I'll try check it in more clear example. For now I believe the issue can be closed. |
This issue was newly affecting me after instructing Babel to not transpile module syntax. As sokra described, it only occurred when trying to use CommonJS style |
I find myself also being bitten by this issue since upgrading to
I'm sorry that I can't provide any more details at this time. |
I'm not at all familiar with the internals but a quick, manual binary search suggests the regression is here: v2.2.0-rc.4...v2.2.0-rc.5 Attn: @sokra, @TheLarkInn I think this issue should be re-opened. |
Taking a quick glance, this is definitely the culprit:
As it says, From my PoV it seems like Webpack's new behavior ultimately makes a lot more sense than the old behavior. It is fairly inane to allow mixing of |
Maybe add this info to migration guide? |
I can only speak for myself, but for the situation affecting me the module within which |
@ggoodman are you using babel-runtime? |
@sokra here are the relevant config files: .babelrc: {
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}]
],
"plugins": ["transform-runtime", "syntax-dynamic-import"]
} webpack.config.js (simplified): 'use strict';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const Path = require('path');
const Webpack = require('webpack');
const config = {
cache: true,
devtool: process.env.NODE_ENV !== 'production' ? 'source-map' : false,
context: Path.join(__dirname),
output: {
path: Path.join(__dirname, 'build'),
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: '/static/',
},
recordsPath: Path.join(__dirname, 'recordsCache'),
module: {
rules: [{
test: /\js$/,
exclude: /node_modules/,
use: [
{
loader: 'ng-annotate-loader',
},
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
{
loader: 'string-replace-loader',
options: {
multiple: [
{ search: /API_URL/g, replace: process.env['PLUNKER_API_URL'] },
{ search: /EMBED_URL/g, replace: process.env['PLUNKER_EMBED_URL'] },
{ search: /RUN_URL/g, replace: process.env['PLUNKER_RUN_URL'] },
{ search: /SHOT_URL/g, replace: process.env['PLUNKER_SHOT_URL'] },
{ search: /WWW_URL/g, replace: process.env['PLUNKER_WWW_URL'] },
],
},
},
]
},
],
},
plugins: [
new ExtractTextPlugin({
filename: '[name].css',
disable: false,
allChunks: true,
}),
],
resolve: {
modules: [
Path.join(__dirname, 'node_modules'),
Path.join(__dirname, 'src'),
],
},
};
module.exports = config; |
Chiming in as I'm getting this error in the browser as well, but neither the requiring module, nor the required module have any |
|
@sokra I was not aware that this plugin would add If removing that plugin is a solution, what alternative can we consider so that we don't have |
The way I see it, there are a few good solutions:
|
How i can reproduce module.exports behavior? |
adding |
I had the following
And was able to fix this by removing the |
M |
see webpack/webpack#4039 for weird issue
In my react-native-web case, just use an additional webpack rule, then the npm install --save-dev react-app-rewired Create a
Also create a
Now you can just run |
@flyskywhy thanks a lot, this saved me a day of work!!!! Sending karma your way 👏 |
Had a weird issue w/ imports or something when setting this up, that was solved with this: webpack/webpack#4039 (comment) Looks like it had to do w/ Babel transpiling (or not) modules in node_modules.
Just a remind, see #4039 (comment) to fix this problem |
Use a helper module with the links. The culprit was that `require` doesn't mix with `module.exports`. You can mix require and export. You can't mix import and module.exports. webpack/webpack#4039 . Still have to see why index.js works fine though.
Hardcoded module.exports breaks webpack when importing the ES module build. I've removed the add-module-exports plugin since it works only when the default export is the only export, which isn't the case for `stream-tag`. Instead, I'm patching the commonjs build after the fact. Related: webpack/webpack#4039
…e build. I've removed the `add-module-exports` plugin since it works only when the default export is the only export, which isn't the case for `stream-tag`. Instead, I'm patching the commonjs build after the fact. Related: webpack/webpack#4039
Hardcoded `module.exports` breaks webpack when importing the ES module build. I've removed the `add-module-exports` plugin since it works only when the default export is the only export, which isn't the case for `stream-tag`. Instead, I'm patching the commonjs build after the fact. Related: webpack/webpack#4039
https://babeljs.io/docs/en/options#sourcetype
Given that the default for |
just like this const Datastore = require("nedb");
function DB(database) {
let options = {
filename: database,
autoload: true,
};
this.db = new Datastore(options);
}
DB.prototype.limit = function(offset, limit) {
this.offset = offset || 0;
this.limit = limit || 15;
return this;
};
DB.prototype.sort = function(orderby) {
this.orderby = orderby;
return this;
};
/**
* query: Object类型 查询条件 支持使用比较运算符($lt, $lte, $gt, $gte, $in, $nin, $ne), 逻辑运算符
* offset: 偏移量 忽略多少条 用于分页
* limit: 返回条数 用于分页
* 返回: docs 数组 返回查询到的数据
* * */
DB.prototype.find = function(query, select) {
return new Promise((resolve, reject) => {
let stmt = this.db.find(query || {});
if (this.orderby !== undefined) {
stmt.sort(this.orderby);
}
if (this.offset !== undefined) {
stmt.skip(this.offset).limit(this.limit);
}
if (select != undefined) {
stmt.projection(select || {});
}
stmt.exec((err, docs) => {
if (err) {
return reject(err);
}
resolve(docs);
});
});
};
/**
* query: object 查询条件
* 查找一条
* 返回: 查到数据
* * */
DB.prototype.findOne = function(query, select) {
return new Promise((resolve, reject) => {
let stmt = this.db.findOne(query || {});
if (this.sort !== undefined) {
stmt.sort(this.sort);
}
if (select != undefined) {
stmt.projection(select || {});
}
stmt.exec((err, doc) => {
if (err) {
return reject(err);
}
resolve(doc);
});
});
};
/**
* 插入数据
* value: 插入的数据
* 使用array,实现批量插入。一旦其中一个操作失败,所有改变将会回滚。
* * */
DB.prototype.insert = function(values) {
return new Promise((resolve, reject) => {
this.db.insert(values, (err, newDoc) => {
if (err) {
return reject(err);
}
resolve(newDoc);
});
});
};
/**
* 更新数据
* query: object 查询的数据
* values: 更新的数据
* options : object muti(默认false),是否允许修改多条文档;upsert(默认为false)
* * */
DB.prototype.update = function(query, values, options) {
return new Promise((resolve, reject) => {
this.db.update(
query || {},
values || {},
options || {},
(err, numAffected) => {
if (err) {
return reject(err);
}
resolve(numAffected);
}
);
});
};
/**
* 根据options配置删除所有query匹配到的文档集。
* query: 与find和findOne中query参数的用法一致
* options: 只有一个可用。muti(默认false),允许删除多个文档
* * */
DB.prototype.remove = function(query, options) {
return new Promise((resolve, reject) => {
this.db.remove(query || {}, options || {}, (err, numAffected) => {
if (err) {
return reject(err);
}
resolve(numAffected);
});
});
};
// module.exports = (database) => {
// return new DB(database);
// };
const nedb = (database='testdb') => {
return new DB(database);
};
export default nedb const db = require("./nedb.js").default("testdb"); |
fixes bug with webpack webpack/webpack#4039
Sharing tailwind config across react components is a bit of a pain. I could fix my issue after reading this one: tailwindlabs/tailwindcss#1853 that uses the preval plugin refs tailwindlabs/discuss#50 webpack/webpack#4039 storybookjs/storybook#5298
…ebpack@5 cause `Uncaught ReferenceError: exports is not defined` , ref to webpack/webpack#4039 (comment)
…webpack@5 cause `Uncaught Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ./node_modules/@flyskywhy/react-native-gcanvas/index.js`, ref to webpack/webpack#4039 (comment)
Uh oh!
There was an error while loading. Please reload this page.
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Module with code
Gives error:
Appeared after upgrade webpack 2.2.0.rc.6 -> 2.2.0.
If 'harmony-module' is ES2015 module, then looks like it's now impossible to mix
require
andexport default
in single module. If it so, that's okay, but should be mentioned in docs.Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
MacOS 10.12.2
node.js 6.9.2
webpack 2.2
The text was updated successfully, but these errors were encountered: