serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

Error importAssertions

Open robertocerdasilva opened this issue 3 years ago • 10 comments

Hello good day.

I have an API that uses json files on some endpoints. I am using NODE 16 and when starting the application on local server, the console requires me to use assert { type: 'json' } when importing json files:

import FILE from 'file.json' assert { type: 'json' }

When executing serverless deploy the console shows the following error:

Support for the experimental syntax 'importAssertions' isn't currently enabled

Helpme plis :( thanks

serverless.yml

plugins:
    - serverless-bundle
    
custom:
    bundle:
        sourcemaps: false
        linting: false
        ignorePackages:
            - pg-native

robertocerdasilva avatar Jun 24 '22 13:06 robertocerdasilva

Hello @jayair , Is there any solution for this?

both alternatives of this article: https://www.stefanjudis.com/snippets/how-to-import-json-files-in-es-modules-node-js/ do not work in production (AWS Lambda)

Thanks

robertocerdasilva avatar Jul 04 '22 16:07 robertocerdasilva

The problem is the depreciated "babel-eslint" missing "importAssertions" in its plugins list. I replaced "babel-eslint" with "@babel/eslint-parser" and modified some of the settings in order to support import assertions. I made a quick fix on my side, but don't have time to do a proper pull request for this. Take a look at this commit:

https://github.com/aresn/serverless-bundle/commit/c503ce6aa8b73a19f34cd8abecdcaf73714091c0

aresn avatar Jul 04 '22 18:07 aresn

@aresn Hello, thanks for answering.

How can I apply this solution locally in detail and not wait for an update of this dependency?

This situation has me somewhat complicated when starting my APIs locally and then having to deploy by modifying the lines where JSON files are imported.

Thanks a lot

robertocerdasilva avatar Aug 12 '22 15:08 robertocerdasilva

Hi @jayair good day. Is it possible to add a solution for this problem?

robertocerdasilva avatar Aug 22 '22 14:08 robertocerdasilva

I haven't had a chance to look at this. If there's a PR that I can review, I'll take a look and merge it.

jayair avatar Aug 22 '22 16:08 jayair

Thank you @jayair, I will be pending. I'm a bit stuck with this solution.

robertocerdasilva avatar Sep 02 '22 17:09 robertocerdasilva

@jayair Hello! is it possible to know if there is an update planned for this problem?

thank you

robertocerdasilva avatar Dec 27 '22 13:12 robertocerdasilva

After waiting so long for this problem, I have implemented @aresn solution.

Anyway thank you very much :)

robertocerdasilva avatar Mar 22 '23 23:03 robertocerdasilva