Reputation: 313
I'm learning to code on my own so to practice webscraping I thought I'd make a program which displays a famous persons birth on a user inputted date on one side using cheerio, while on the other it uses an API to get the temp of a user inputted city. Here is the github: https://github.com/Yummy275/Date_Weather_Celebbirths
Im having trouble with famous_getter.js in ./src . When I try to add export { getName }
to be able to use the function in other files similar to all my other files, I get an error when I try to webpack or run node famous_getter.js after I add import {getName} from "./famous_getter"
to index.js to test the function. Any help is appreciated. Thanks for looking.
EDIT - adding errors
Webpack error(its this repeated a bunch for different things "cant resolve 'x" in":
ERROR in ./node_modules/request/lib/har.js Module not found: Error: Can't resolve 'fs' in '/home/yummy/Projects/DateWeatherCelebbday/node_modules/request/lib' @ ./node_modules/request/lib/har.js 3:9-22 @ ./node_modules/request/request.js @ ./node_modules/request/index.js @ ./src/famous_getter.js @ ./src/index.js
node famous_getter.js error:
node famous_getter
(node:257160) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/yummy/Projects/DateWeatherCelebbday/src/famous_getter.js:25
export { getName };
^^^^^^
SyntaxError: Unexpected token 'export'
In my GitHub famous_getter.js works when I run node famous_getter.js . When I get rid of my test (getName(famousbirthsURL)) and try to add export {getName}, thats when errors happen.
Upvotes: 0
Views: 1259
Reputation: 1203
Attempt #2:
Edit: I have taken all edits to the OP's question and info in comments in this response.
Looks like you are targeting node and not web. The default target for webpack is web. You need to add a target: 'node' in your webpack file.
const path = require("path");
module.exports = {
target: 'node',
entry: "./src/index.js",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
};
After adding this, webpack ran successfully and built the assets.
Launched http-server ./ on the dist folder and browsed home page. Screenshot:
I downloaded the project from Github and ran webpack.
The assets are building successfully.
I also added the export { getName } to famous_getter.js and ran webpack.
Build is successful. I am not encountering the errors.
Perhaps, something is wrong with your environment or node_modules cache. Try a fresh install and webpack.
Screenshots below:
Upvotes: 2
Reputation: 6872
Lets read the error thoroughly: Error: Can't resolve './src/index.js' in '/home/yummy/Projects/DateWeatherCelebbday/src'
.
index.js
that's located at the relative position ./src/index.js
. The .
at the begining means that we are trying to resolve the path in a relative manner./home/yummy/Projects/DateWeatherCelebbday/src
. In other words the
program is looking for a file at
/home/yummy/Projects/DateWeatherCelebbday/src/src/index.js
, which
likely contain one too many src
../index.js
, or navigate to /home/yummy/Projects/DateWeatherCelebbday
and run the original command.Upvotes: 1