Answer the question
In order to leave comments, you need to log in
How to write a js file so that it can be picked up in both webpack and node?
I write like this
function fnTest(line) {
return line.split('');
}
// Добавить правило в очередь правил
module.exports = function (line) {
return [].concat(fnTest(line),fnTest(line+line));
};
I get the error "Uncaught TypeError: Cannot assign to read only property 'exports' of object" in the browser (building via Vue CLI) Answer the question
In order to leave comments, you need to log in
Apparently, the point here is not in export, but in the line.split function
As a solution, I replaced str.split with
For full-scale projects, you can use https://www.npmjs.com/package/esmnode -r esm <js файл>
First, never put ; after export.
Secondly, you need to export the function, and call it in the file
From where we export (let's say func.js)
function fnTest(line) {
console.log('line', line.split(''));
}
// Добавить правило в очередь правил
module.exports = { fnTest }
const { fnTest } = require('func')
fnTest('aaa')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question