fourTheorem / slic-watch

Instant alarms and dashboards for Serverless, SAM, CDK and CloudFormation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can't use slic-watch-core without a bundler

JamesKyburz opened this issue · comments

Describe the bug

I was going to start writing a sam plugin for this for sam-expand however found that slic-watch-core couldn't be imported or required. This is because the file is .js, the module isn't type module, and there aren't any package.json exports.

slic-watch-core doesn't work with require or import.

To Reproduce
Steps to reproduce the behavior:

~ ᐅ nvm use 20
Now using node v20.11.0 (npm v10.2.3)
~ ᐅ mkdir -p /tmp/slic-test
~ ᐅ ^mkdir -p^cd
~cd /tmp/slic-test
/tmp/slic-test ᐅ npm init -y &>/dev/null && npm i slic-watch-core &>/dev/null
/tmp/slic-test ᐅ node
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> require('slic-watch-core')
/private/tmp/slic-test/node_modules/slic-watch-core/dist/index.js:27
import { get, merge } from "lodash";
^^^^^^

Uncaught:
SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import:
> import('slic-watch-core')
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 141,
  [Symbol(trigger_async_id_symbol)]: 6
}
> (node:58578) 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)
/private/tmp/slic-test/node_modules/slic-watch-core/dist/index.js:27
import { get, merge } from "lodash";
^^^^^^

Uncaught:
SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import:

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots, Input Files and Logs
If applicable, add screenshots, CloudFormation templates, serverless configuration and/or logs to help explain your problem.

Environment:

  • OS: macOS
  • Node.js Version: v20.11.0
  • NPM version: v10.2.3
  • Serverless Framework Version: n/a

Additional context
It's been broken since version 3.0.0, v2 worked with both require and import.

Thanks for this @JamesKyburz. It makes sense from a first look. We are planning on a separate, library version of slic-watch-core so this is good to know about. We are just going to test all permutations of the PR before merge and release.