jbrooksuk / node-summary

Node module that summarizes text using a naive summarization algorithm

Home Page:http://jbrooksuk.github.io/node-summary/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seeing import _ from 'lodash' error

sidster-io opened this issue · comments

commented

node_modules/node-summary/lib/summary.js:1
(function (exports, require, module, __filename, __dirname) { import _ from 'lodash'

on node version v11.6.0

Can you try the version on master?

commented

Sorry for the late reply. Will try it out 👍🏽

commented

Running into a new issue.
Added "node-summary": "git+https://github.com/jbrooksuk/node-summary.git#master" to package.json
Seeing error /node_modules/node-summary/lib/summary.js:1 (function (exports, require, module, __filename, __dirname) { import { convertHTMLToText, getTitle } from './helpers/html'

Same error as @sidster-io from the master branch. @jbrooksuk maybe you need to add "type": "module" to the package.json?

Same error here, v14.1.0

Same error as @sidster-io from the master branch. @jbrooksuk maybe you need to add "type": "module" to the package.json?

Possibly! I'm not overly familiar with how this works to be honest. Are you able to test this?

I think the problem is that you are using ES syntax along with CommonJS. You could try going through the code and make it work with CommonJS syntax. What I mean is changing statements like import {convertHTMLToText, getTitle} from './helpers/html.js'; to
const {convertHTMLToText, getTitle} = require("./helpers/html.js");. You would also have to change export statements from export const getTitle = htmlBody = {<function code here>} to module.exports.getTitle = (htmlBody) => {<function code here>}

I created a pull request fixing this issue(#50). You can use that instead the main package by using the command (or just wait him fix the issue / or merge the PR):
npm install https://github.com/TroniPM/node-summary

@jbrooksuk Looks like the master version is not in npm and the issue continues. Can you please publish master version to npm ?
Screenshot 2021-02-03 at 4 27 59 PM
Screenshot 2021-02-03 at 4 28 35 PM

/node_modules/node-summary/lib/summary.js:1
import _ from 'lodash'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1067:16)
    at Module._compile (internal/modules/cjs/loader.js:1115:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)

on windows with node v16.14.0

import _ from 'lodash'
^^^^^^

SyntaxError: Cannot use import statement outside a module

I created a pull request fixing this issue(#50). You can use that instead the main package by using the command (or just wait him fix the issue / or merge the PR): npm install https://github.com/TroniPM/node-summary

This works fine. Thank you

npm install https://github.com/TroniPM/node-summary

This still works like a charm! Thank you!