I'm new to Vue. I have a Vue file and in the section I use an import command.
<script>
import Module from '../module.js'
module.js uses module.exports.example1 = function() { return true }
However, this fails with the error: Uncaught TypeError: Cannot set property 'example1' of undefined
When I do console.log(module) it also shows exports as undefined.
Why is exports undefined? Is there a better place I should place this module?
Related
I was trying to run tests using supertest in nodejs and I got this error message
ReferenceError: TextEncoder is not defined
Then i was advised to locate the file "node_modules/whatwg-url/lib/encoding.js" and add this lines of code at the top
const { TextEncoder, TextDecoder } = require("./utils");
After i did that, i started getting this message
TypeError: TextEncoder is not a constructor
please, i am using node version 17.4.0
What I need:
Read a local JSON file inside NuxtJS as the page loads. So I can parse it into a prop within <option> tag.
What I have:
Lowdb (installed as dependency — to read the JSON file) inside a component, with this code:
computed: {
resultFetchCamera: function() {
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json');
const db = low(adapter);
let value = db.get('Size').map('Name').value();
return value;
}
}
}
I got an error This dependency was not found: * fs in ./node_modules/lowdb/adapters/FileSync.js. Fixed with this solution. Which leads me to another error: TypeError: fs.existsSync is not a function. This solution helps out a bit but it also leads to other errors: TypeError: window.require is not a function and TypeError: FileSync is not a constructor. So, I undo the last solution and get back with the fs.existsSync error.
The question:
How to fix the fs.existsSync error (in a NuxtJS environment)?
Did I implement Lowdb to NuxtJS correctly?
I am building a webservice with Node and Vue. I built backend Node modules which are all working as expected. But when I try to import those in my Vue SFC script, I am getting 'stream undefined' error.
My hunch is that I am mixing CommonJS and ES6 styles of exporting and importing and that is causing the issue because when I created a temporary module with just one function and no require or import statements and use module.exports to expose that function and then call import in Vue SFC, it is working. But when I use require statements in the module, I am getting the stream undefined error again. I tried multiple solutions I found online but I am not able to get it to work.
My (temporary) node module, temp.js. This doesn't work:
require('./auth.js');
function test(){
console.log('Test method');
}
module.exports = {test};
This works:
function test(){
console.log('Test method');
}
module.exports = {test};
My SFC script:
<script>
import * as temp from './temp.js';
export default {
name: 'Dashboard'
}
</script>
I have a npm package of React components and an example Meteor.js app which will be used to display their usage. To install my local npm package I ran npm install --save ../library and it successfully added the dependency as "library": "file:///path/to/lib".
However, when I import one of the components and try to use them, the console spams 29 errors, starting with:
Uncaught SyntaxError:
Unexpected token import
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'Random' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'MongoID' of undefined
The code:
import React, { PropTypes } from 'react';
import Button from 'library/components/button/Button.jsx'
export default class App extends React.Component {
render() {
return (
<div>
<Button>Click Me</Button>
</div>
);
}
}
Removing the <Button/> component and it's import removes the error. What is going on here?
EDIT: Digging deeper, if I click on the Unexpected token import error, it shows me the line where I import React in my libraries Button component. Could the issue be related to it somehow not understanding ES6 imports properly?
I can't figure out why I get an undefined here for 'app':
module.exports = {
application: require('../../app').service,
request: require('supertest')(this.application),
startSetup: setup(this.application)
};
it throws up at the (this.application) for the request: line.
Yo can try this:
var app = require('../../app').service;
module.exports = {
application: app,
request: require('supertest')(app),
startSetup: setup(app)
};
The problems is that this.application doesn't exists yet.
You can't use the inside parts of an object that it is not defined (it is defined only after the final }).
Here is an example that you can try on your chrome console.
You can see that you can't use type because it is not defined.
Javascript doesn't know what this.application is. The object hasn't been defined yet so you can't use an attribute inside at object definition that's defined in the same object.